zoukankan      html  css  js  c++  java
  • 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');
    
        }
  • 相关阅读:
    JS reduce方法的使用
    面试娱录
    sticky置顶功能影响了锚点定位
    postcss-px-to-viewport移动端自适应
    axios请求参数自动拼接到了地址那里
    ping 不通。无法访问目标主机
    JS前后台方法的相互调用
    SQL server2008 无法连接服务器
    Assembly.Load未能加载文件或程序集“”或它的某一个依赖项。系统找不到指定的文件
    JS判断IE和非IE
  • 原文地址:https://www.cnblogs.com/hnbiao/p/6533593.html
Copyright © 2011-2022 走看看