Thinkphp 带查询条件数据分页

时间:2022-01-20 08:26:41
 //查询条件中如果有中文
$keyword= urldecode(I("request.keyword"));
if ($keyword!=""){
$Model = new \Think\Model(); //SQL查询条件
$condition['name'] = array('like',"%".$keyword."%");
$condition['nickname'] = array('like',"%".$keyword."%");
$condition['telephone'] = array('like',"%".$keyword."%");
$condition['_logic'] = 'OR'; $count = $Model->table('userinfo')->where($condition)->count();
$Page = new \Think\Page($count,10); //查询条件带入参数
$map['keyword'] = $keyword;
foreach($map as $key=>$val) {
$Page->parameter[$key]=urlencode($val);
}
$show = $Page->show();// 分页显示输出
$list=$Model->table('userinfo')->where($condition)->limit($Page->firstRow.','.$Page->listRows)->select(); $this->assign('page',$show);// 赋值分页输出
$this->assign('list',$list);
}
$this->display();