• thinkphp 分页


        //换一种思路
        /*
            或许有的时候数据并不是全都是从库里面查出来的吧!
            那天遇到一个就是先查出库里面的数据,然后在通过条件判断,得到一个数组!
            这个时候用到分页了,怎么整?看看
        */
        public  function array_page($array,$rows){
            $count=count($array);
            $Page=new Page($count,$rows);
            $list=array_slice($array,$Page->firstRow,$Page->listRows);
            return $list;
        }

    注意:html 表单必须用get  而不能用post 提交

    完整代码
    
        //列表分页查询
        
        public function list_select(){
            $cat_id=intval($_REQUEST['cat_id']);
            if($cat_id!=0){
                $map['b.cat_id']=intval($_REQUEST['cat_id']);
    
            }
            if($_REQUEST['start_time']!="" && $_REQUEST['end_time']==""){
                $start_time=strtotime($_POST['start_time']);
                $map['b.create_time']=array('gt',"$start_time");
            }
            if($_REQUEST['start_time']!="" && $_REQUEST['end_time']!=""){
                $start_time=strtotime($_REQUEST['start_time']);
                $end_time=strtotime($_REQUEST['end_time'])+24*60*60-1;
                $map['b.create_time']=array('between',"$start_time,$end_time");
            }
            if($_REQUEST['title']!=""){
                $title=$_REQUEST['title'];
                $map['b.title']=array('like',"%$title%");
            }
            if(empty($map)){
                $map="1=1";
            }
            $data=$this->Model->table(array('blog'=>'b'))->field('b.id,c.cat_title,b.cat_id,b.title,b.description,b.content,b.cover_id,b.update_time')
            ->join('category c on c.id=b.cat_id')->where($map)->order('id desc')->select();
            // echo $this->Model->getLastSql();
            $count=count($data);
            $Page=new Page($count,8,$parameter);
            $show=$Page->show();
            $list=array_slice($data,$Page->firstRow,$Page->listRows);
            $this->assign('list',$list);
            $this->assign('page',$show);
            $this->category();
            $this->display('index');
    
        }
  • 相关阅读:
    bzoj3530 [SDOI2014]数数
    bzoj3940 Censoring
    线性代数基础
    hdu1085 Holding Bin-Laden Captive!
    hdu1028 Ignatius and the Princess III
    luogu2000 拯救世界
    博弈论入门
    树hash
    luogu2173 [ZJOI2012]网络
    luogu1501 [国家集训队]Tree II
  • 原文地址:https://www.cnblogs.com/hnbiao/p/6533593.html
Copyright © 2020-2023  润新知