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');
    
        }
  • 相关阅读:
    Java中二进制数与整型之间的转换
    校招小白机考入坑之从键盘输入java的各种数据类型
    使用flume抓取tomcat的日志文件下沉到kafka消费
    Scala学习笔记之Actor多线程与线程通信的简单例子
    通过流的方式操作hadoop的API
    Windows环境下使用kafka单机模式
    scrapy
    python 虚拟环境
    celery使用
    redis install
  • 原文地址:https://www.cnblogs.com/hnbiao/p/6533593.html
Copyright © 2011-2022 走看看