/***************************************************** *********************************
* Perfect paging class, you can customize the paging (perfect than Teacher Gao Pang’s, O(∩_∩)O haha~)
*************************************************** ************************************
*Copyright (C) 2011-2012 North Sea Love Letters - A Programmer's Blog, all rights reserved. *
************************************************* *********************************
* $Author: Beihai Love Letter (hackmyth@163.com) $
* $Date: 2011-07-18 10:00:00 $
************************************************* **********************************/
class Page{
Private $ Total; // Total number of data
private $listRows;
private $limit; //Limit the number of items
private $pageNum;
Private $ page; // The current page
private $config=array('head'=>"record", "prev"=>"previous page", "next"=>"next page", "first"=>"home page" , "last"=>"Last page");
/**
*Constructor method, you can set the attributes of the paging class
* @param int $listRows Optional, the default number of records to be displayed on each page
*
*/
public function __construct($total,$listRows=10){
$this->total=$total;
$this->listRows=$listRows;
$ This-& gt; pagenum = Ceil ($ this-& gt; topal/$ this- & gt; listRows); // Get the total number of pages
If ($ _ get ['page'] & gt; $ this- & gt; pagenum) {// Prevent the boundary
$_GET['page']=$this->pageNum;
}
$this->page=!empty($_GET['page'])?$_GET['page']:"1"; //Current page
$ This-& gt; limit = $ this- & gt; setpage (); // paging formula
}
public function __get($args){
If ($ args == 'limit') {// Filter illegal request
return $this->limit;
}
return null;
}
//Calculate paging formula
private function setPage(){
return "limit ".($this->page-1)*$this->listRows.",".$this->listRows;
}
//上一页
private function prev(){
return "".$this->config['prev']."";
}
//下一页
private function next(){
return "".$this->config['next']."";
}
//首页
private function first(){
return "".$this->config['first']."";
}
//尾页
private function last(){
return "".$this->config['last']."";
}
//分页列表
private function pagelist(){
$lists.='';
for($i=1;$i<$this->pageNum;$i++){
$lists.="$i ";
}
return $lists;
}
public function fpage($display=array(1,2,3,4,5)){
$html[1]= "共有".$this->total.$this->config['head'];
$html[2]= $this->prev(); //上一页
$html[3]= $this->next(); //下一页
$html[4]= $this->first(); //首页
$html[5]= $this->last(); //尾页
$html[6]= $this->pagelist(); //列表
$fpage='';
foreach($display as $index){
$fpage.=$html[$index];
}
return $fpage;
}
}
|