tp3.2.3搜索分页

$obj=M(‘users’);
$tj=””;
//$condition[‘uid’] = array(‘like’,’%’.$keyword.’%’);
if(I(“get.”)){
$keyword=I(“get.keyword”);
//$tj=” username like ‘%”.$keywords.”%'”;
$s[‘username’] = array(‘like’,’%’.$keyword.’%’);
      /* $condition[‘usertype’] = array(‘neq’,2);
        $condition[‘uid’] = array(‘like’,’%’.$keyword.’%’);
        $condition[‘status’] = $status;
        $condition[‘sex’] = $sex;*/
}
$num=3;//设置一页分多少条
$count=$obj->where($s)->count();//计算总记录数
$Page= new \Think\Page($count,$num);// 实例化分页类 传入总记录数和每页显示的记录数(25)
$arr=$obj->order(‘id desc’)->where($s)->limit(“$Page->firstRow,$Page->listRows”)->select();
//print_r($arr);
print_r( $Page->parameter);
$Page->setConfig(‘prev’,’上一页’);//一定要放到$Page->show();之上才有效!
$Page->setConfig(‘next’,’下一页’);
$map[‘keyword’] = $keyword;
$Page->parameter = array_map(‘urlencode’,$map);  //将parameter变成字符串形式,导致无法翻页。所以选择第二种。
//array_map是将函数作用到数组的每个元素上。
$show= $Page->show();// 分页显示输出
//echo $show;
$this->assign(‘show’,$show);
$this->assign(‘arrlist’,$arr);
$this->display(“/list”);

关注公众号,了解更多it技术(it问答网

发表评论

电子邮件地址不会被公开。