简单的一个php分页类

<?php
class Pages{
public $page_total;//总记录数
protected $page; //当前页
protected $page_size;//每页显示的记录数
protected $page_num;//总页数
protected $url;
protected $next_page;//下一页
protected $prve_page;//上一页
public $statr_page;//当页的开始位置
public $end_page;//末页
protected $first="首页";
protected $last="末页";
protected $next="下一页";
protected $prve="上一页";


    function __construct($page_total,$page_size,$url){
        $this->page = isset($_GET['page'])? $_GET['page']:1;
        //$this->currpage();
        $this->page_total=$page_total;
        $this->page_size=$page_size;
        echo $this->url=$url;
        $this->page_num=$this->getpagenum();
        $this->next_page=$this->getnextpage();
        $this->prve_page=$this->getprvepage();
        $this->statr_page=$this->getstatr();
        $this->end_page=$this->getend();
    }
    /*function currpage(){
      if(isset($_GET['page'])){
           return $this->page=$this->$_GET['page'];
        }else{
            return $this->page=1;
        } 
    }*/
    function getpagenum(){
        return ceil($this->page_total/$this->page_size);        
    }
    function getnextpage(){
        if($this->page==$this->page_num){
            return  $this->page_num;
        }else{
            return ($this->page+1);
        }
    }
    function getprvepage(){
        if($this->page==1){
            return false;
        }else{
            return $this->page-1;
        }
    }   
    function getset(){
        return ($this->page-1)*($this->page_size);
    }
    //当前页开始的记录数
    function getstatr(){
         if($this->page_total==0){
            return 0;
         }else{
            return $this->getset()+1;
         }
    }
    //当前页结束的记录数
    function getend(){
        return min($this->getset()+$this->page_size,$this->page_total);
    }
    
    function getpage(){
        $pinfo="共<b>($this->page_total)</b>记录.本页显示的是($this->statr_page)--($this->end_page)条  "
                ."($this->page)/($this->page_num)  ";
    if($this->page==1){
        $pinfo.=$this->first."  ";
    }else{
        $pinfo.="<a href=".$this->url."?page=1>".$this->first."</a>  ";
    }
    if($this->prve_page){
        $pinfo.="<a href=".$this->url."?page=".$this->prve_page.">".$this->prve."</a>  ";
    }else{
        $pinfo.=$this->prve."  ";
    }
    if($this->next_page){
        $pinfo.="<a href=".$this->url."?page=".$this->next_page.">".$this->next."</a>  ";
    }else{
        $pinfo.=$this->prve."  ";
    }
    if($this->page==$this->page_num){
        $pinfo.=$this->last."  ";
    }else{
        $pinfo.="<a href=".$this->url."?page=".$this->page_num.">".$this->last."</a>  ";
    }
    print $pinfo;
//    echo $this->page;
    }    
   
}


$page_new= new Pages(100, 10, $_SERVER["PHP_SELF"] );
$page_new->getpage();


?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值