think php5 多表查询分页 获取总数的代码方法
程序员文章站
2023-09-11 11:15:25
控制器
$data = input('get.');
$info = [];
//搜索条件
if(!e...
控制器
$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 ]);
模型内
$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;