Thinkphp3.2 分页查询 (带参数)

首先是 借鉴 的代码

   //商品列表页面
    public function  index(){
        $name= I('get.name') ? I('get.name') : "";//商品名称
        $advertiser_id= I('get.advertiser_id') ? I('get.advertiser_id') : "";//广告主id
        $start_time = I('get.start_time') ? I('get.start_time') : "";
        $end_times = I('get.end_time') ? I('get.end_time') : "";
        $end_time = $end_times." 23:59:59";
        $s1 = strtotime($start_time);//开始的时间戳
        $e1 = strtotime($end_time);//结束的时间戳
        $where = [];
        if($name)
        {
            $where['ap.name'] = array('like',"%$name%");
        }
        if($advertiser_id)
        {
            $where['ap.advertiser_id'] = $advertiser_id;
        }
        if($s1 && $e1 !==''){
            $where['ap.add_time'] = array('between',array($s1,$e1));
        }
        $p_num= 2;
        $count  =  D('ApiProduct')->counts($where);// 查询满足要求的总记录数
        $Page   = new \Think\Page($count,$p_num);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $page_begin= $Page->firstRow;
        //搜索条件
        $map['name'] = $name;
        $map['start_time'] =  $start_time;
        $map['end_time'] =  $end_times;
        $map['advertiser_id'] =  $advertiser_id;
        $Page->parameter = array_map('urldecode',$map);
        $show = $Page->show();// 分页显示输出
        $list = D('ApiProduct')->allDatas($where,$page_begin,$p_num);
        $wheres=[];
        $lists = D('ApiAdvertiser')->allData($wheres);//查询广告主
 
        $this->assign("page", $show);
        $this->assign('list',$list);
        $this->assign('name',$name);
        $this->assign('options', $lists);
        $this->assign('start', $start_time);
        $this->assign('end', $end_times);
        $this->display();
 
    }

主要代码

//后台PHP文件
public function index(){
        $name = I('name');
        if(!empty($name)){
            $where['name'] = array('like','%'.$name.'%');;
            $val['name'] = $name;
        }
        $remark = I('remark');
        if(!empty($remark)){
            $where['remark'] = array('like','%'.$remark.'%');
            $val['remark'] = $remark;
        }
        $job = I('job');
        if(!empty($job) && $job>0){
            $where['job'] = $job;
            $val['job'] = $job;
        }
        $table = M('summit');
        $count = $table->where($where)->count();
        $Page = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        //分页跳转的时候保证查询条件
        $Page->parameter = array_map('urldecode',$val);
        $show = $Page->show();// 分页显示输出
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $table->where($where)->order('register_time desc')->limit($Page->firstRow.','.$Page->listRows)->select();

        $this->assign('val',$val);
        $this->assign('list',$list);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出
        $this->display();
}
//前台 html 
 
姓名 手机号 企业全称 职务 参会类别 推荐人 是否参保 身份证号 是否支付 支付时间 是否签到 签到时间 报名时间
{$v.name} {$v.phone} {$v.company} {$v.job} {$v.congress_type} {$v.remark} {$v.is_insure} {$v.idcard} {$v.status} {$v.status} {$v.pay_time} {$v.is_sign} {$v.sign_time} {:date('Y-m-d H:i:s',$v['register_time'])}
{$page}

你可能感兴趣的:(Thinkphp3.2 分页查询 (带参数))