当前位置:Gxlcms > PHP教程 > php简单分页类_PHP教程

php简单分页类_PHP教程

时间:2021-07-01 10:21:17 帮助过:21人阅读

/**
* 分页类
* 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的专栏

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478369.htmlTechArticle?php /** * 分页类 * 2011/8/31 * kcj * */ class Page{ private $total; //查询总的数据记录 private $page; //当前第几页 //private $pagesize; //每页显示的条数 priv...

人气教程排行