標籤: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 分頁