Home > php教程 > php手册 > body text

php简单分页类

WBOY
Release: 2016-06-13 10:47:41
Original
978 people have browsed it

/**
 * 分页类
 * 2011/8/31
 * kcj
 * */ 
class Page{ 
    private  $total;     //查询总的数据记录  
    private  $page;      //当前第几页  
    //private  $pagesize;  //每页显示的条数  
    private  $pagenum;   //总共多少页  
    private  $num;       //每页显示记录的条数  
    private  $offset;    //从数据库中取记录的开始偏移数  
     
    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(){    //下一页  
        if($this->page==$this->pagenum){ 
            return false; 
        }else { 
            return $this->page+1; 
        } 
    } 
    private  function getPrevPage(){ 
        if($this->page==1){            //上一页  
            return false; 
        }else { 
            return $this->page-1; 
        } 
    } 
    private  function getOffset(){ 
        return  ($this->page-1)*$this->num; 
    } 
    private function getStartNum(){ 
        if ($this->total==0) { 
            return 0; 
        }else { 
            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; 
    } 

?> 

摘自 chaojie2009的专栏

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!