thinkphp 分頁

來源:互聯網
上載者:User

標籤:his   php   個數   sts   array   class   mod   last   tle   

    //換一種思路
    /*
        或許有的時候資料並不是全都是從庫裡面查出來的吧!
        那天遇到一個就是先查出庫裡面的資料,然後在通過條件判斷,得到一個數組!
        這個時候用到分頁了,怎麼整?看看
    */
    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‘);    }

 

thinkphp 分頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.