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 
 <form class="js-ajax-form" action="" method="post">
      <table class="table">
       <thead>
       <tr>
                     
        <th>姓名</th>
        <th>手机号</th>
        <th>企业全称</th>
        <th>职务</th>
        <th>参会类别</th>
        <th>推荐人</th>
        <th>是否参保</th>
        <th>身份证号</th>
        <th>是否支付</th>
        <th>支付时间</th>
        <th>是否签到 </th>
        <th>签到时间</th>
        <th>报名时间</th>
       </tr>
       </thead>
       <foreach name="list" item="v">
        <tr>
          <td class="center">{$v.name}</td>
          <td class="center">{$v.phone}</td>
          <td class="center">{$v.company}</td>
          <td class="center">{$v.job}</td>
          <td class="center">{$v.congress_type}</td>
          <td class="center">{$v.remark}</td>
          <td class="center">{$v.is_insure}</td>
          <td class="center">{$v.idcard}</td>
          <if condition="$v['status'] eq '否' "> 
          <td class="center" style="color:#F00">{$v.status}</td>
          <else />
          <td class="center">{$v.status}</td>
          </if>
          <td class="center">{$v.pay_time}</td>
          <td class="center">{$v.is_sign}</td>
          <td class="center">{$v.sign_time}</td>
          <td class="center">{:date('Y-m-d H:i:s',$v['register_time'])}</td>
        </tr>
        </foreach>
            <td colspan="3" bgcolor="#FFFFFF">
                <div class="pages">
                {$page}
                </div>
            </td> 
      </table>
      </form>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 180,076评论 25 708
  • 人生的路上充满了未知!谁也不知道下一刻会发生什么事! 也许多年的劳累工作使你突然病倒,也许家人突发意外,也许工作企...
    一粟于海阅读 343评论 0 3
  • 为了追逐, 一个宁静的梦, 为了美好的明天…… 我们的先辈聚集在了一起。 这地方, 沟沟坎坎, 甚至没有一条路与外...
    水云怒阅读 324评论 1 3
  • 早上,陪小肥脸儿去拿请假条,说实话,没请假过,所以不知道具体流程,她告诉我说,请假条要去小卖部买!天呐!我惊讶了。...
    云淡风轻温暖依旧阅读 392评论 0 1

友情链接更多精彩内容