<?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();
?>