<?php

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;
}
}
?>

創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()