带条件分页

浏览:829 发布日期:2016/07/05 分类:求助交流
参考官方手册上的条件分页,只能显示第一页,点下一页就会跳转到首页了,分页页脚的url也不对,请大家帮忙看一下public function index(){

        if(IS_POST){
            $k = I('keyword');
            $keyword = '%'.$k.'%';
            $map['name|sex|tel|company|comment'] = array('like',$keyword);
            $customer = M('customer');

            //分页
            $mapcount      = $customer->where($map)->count();// 查询满足要求的总记录数
            $Page       = new \Think\Page($mapcount,1);// 实例化分页类 传入总记录数和每页显示的记录数
            //分页跳转的时候保证查询条件
            foreach($map as $key=>$val) {    
                $Page->parameter   .=   "$key=".urlencode($val).'&';
            }
            $show       = $Page->show();// 分页显示输出
            $cs = $customer->limit($Page->firstRow.','.$Page->listRows)->where($map)->select();
            $this->assign('page',$show);// 赋值分页输出

            $this->assign('customers',$cs);
            $this->assign('keyword',$k);
            $this->display();
            return;
        }

        $customer = M('customer');
        //分页
        $count      = $customer->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,2);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show       = $Page->show();// 分页显示输出
        $cs         = $customer->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('page',$show);// 赋值分页输出
        $this->assign('customers',$cs);
        $this->display();
    }
最佳答案
评论( 相关
后面还有条评论,点击查看>>