Home  >  Article  >  Backend Development  >  PHP simple paging class_PHP tutorial

PHP simple paging class_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:49:14843browse

/**
* Pagination class
* 2011/8/31
* kcj
**/
class Page{
private $total; //Query the total data records
Private $page; //The current page
//private $pagesize; //Number of items displayed on each page
Private $pagenum; //How many pages in total
private $num; //Number of records displayed on each page
Private $offset; //Get the starting offset of the record from the database
       
Function __construct($total,$page=1,$num=5){
          $this->total=$total;
          $this->page=$page;
           $this->num=$num;
           $this->pagenum=$this->getPageNum();
          $this->offset=$this->getOffset();
}  
Private function getPageNum(){
Return ceil($this->total/$this->num);
}  
Private function getNextPage(){ //Next page
If($this->page==$this->pagenum){
             return false;
                                                                                         return $this->page+1;
         } 
}  
private function getPrevPage(){
If($this->page==1){                                                                                                                                                                                                                 return false;
                                                                                        return $this->page-1;
         } 
}  
private function getOffset(){
           return ($this->page-1)*$this->num;
}  
Private function getStartNum(){
If ($this->total==0) {
              return 0;
                                                                                        return $this->offset+1;
         } 
}  
private function getEndNum(){
          return min($this->offset+$this->num,$this->total);
}  
Public function getPageInfo(){
         $pageInfo=array(
"row_total"=>$this->total,
"row_num" =>$this->num,
"page_num" =>$this->getPageNum(),
"current_page"=>$this->page,
"row_offset"=>$this->getOffset(),
"next_page"=>$this->getNextPage(),
"prev_page"=>$this->getPrevPage(),
"page_start"=>$this->getStartNum(),
"page_end" =>$this->getEndNum()
);
Return $pageInfo;
}  
}
?>

Excerpted from chaojie2009’s column

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478369.htmlTechArticle?php /*** Pagination class * 2011/8/31 * kcj **/ class Page{ private $total; //Query the total data records private $page; //The current page //private $pagesize; //The number of items displayed on each page private...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn