Home>Article>Backend Development> think php5 multi-table query paging code method to get the total number
I encounter a lot of paging situations in tp5. This article will explain the relevant knowledge.
Controller
$data = input('get.'); $info = []; //搜索条件 if(!empty($data['title'])){ $data['title'] = trim($data['title']); $info['topic_title'] = ['like','%'.$data['title'].'%']; } $list = BeModel::getList($info); $num = $list->total();//获取总数 return $this->fetch('',[ 'list' => $list, 'title' => empty($data['title']) ? '' :$data['title'], 'num' => $num ]);
Inside the model
$search = []; $search['b.status'] = ['neq',-1]; if(!empty($data['topic_title']) ){ $search['b.topic_title'] = $data['topic_title']; } $res = self::alias('b')->join('subject s','s.id=b.subject_id','left') ->join('law l','l.id=b.law_id','left') ->field('b.*,s.subject,l.name') ->where($search) ->order('id asc') ->paginate(4,false,[ 'query' => request()->param(), ]); return $res;
This article explains the paging problem of tp5. For more related content, please pay attention to the php Chinese website.
Function analysis of commonly used functions in php
PHP The simplest implementation method for verifying logged in users (basic form user verification)
The above is the detailed content of think php5 multi-table query paging code method to get the total number. For more information, please follow other related articles on the PHP Chinese website!