這個(gè)分頁類,參考了慕課網(wǎng)和燕十八的分頁類。
成都創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:做網(wǎng)站、網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的上黨網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
慕課網(wǎng)分頁類學(xué)習(xí)網(wǎng)址:http://www.imooc.com/learn/419
效果圖:
class page{
public $cpage; //傳入的頁碼
public $totalnum; //總的記錄數(shù),數(shù)據(jù)
public $total_page; //總頁數(shù)
public $per_page = 10; //每頁的記錄數(shù)
public $showpage = 5; //頁碼條顯示的頁碼個(gè)數(shù)
public $pageoffset; //頁碼條偏移的頁碼個(gè)數(shù)
public $pageup; //上一頁
public $pagedown; //下一頁
public $start=1; //開始頁碼
public $end; //結(jié)束頁碼
public $fycod = array();
//初始化各個(gè)參數(shù)
public function __construct($cpage,$totalnum){
$this->cpage = $cpage;
$this->totalnum = $totalnum;
$this->pageoffset = ($this->showpage-1)/2;
$this->total_page = $this->totalnum/10;
$this->end = $this->total_page;
//總頁數(shù)
$this->total_page = ceil($this->totalnum/$this->per_page);
}
//返回總的頁數(shù)
public function gettotal_page(){
return $this->total_page;
}
//返回每頁的記錄數(shù)
public function getper_page(){
return $this->per_page;
}
//返回當(dāng)前頁
public function getcpage()
{
return $this->cpage;
}
//修改當(dāng)前頁
public function modcpage($cpage){
$this->cpage = $cpage;
}
//返回上一頁
public function getpageup(){
if($this->cpage<=1){
return $this->pageup = 1;
}
return $this->pageup = $this->cpage -1;
}
//返回下一頁
public function getpagedown(){
if($this->cpage < $this->total_page){
return $this->pagedown = $this->cpage+1;
}
}
//返回一個(gè)數(shù)組,關(guān)于頁碼的各個(gè)參數(shù)
public function getpages(){
$pages = array();
$pages['total_page'] = $this->total_page;
$pages['per_page'] = $this->per_page;
$pages['cpage'] = $this->cpage;
$pages['pageup'] = $this->getpageup();
$pages['pagedown'] = $this->getpagedown();
$pages['start'] = $this->start;
$pages['end'] = $this->end;
$pages['pageoffset'] = $this->pageoffset;
$pages['showpage'] = $this->showpage;
return $pages;
}
//分頁代碼函數(shù),返回一個(gè)數(shù)組,作用:分頁的頁碼數(shù)
public function getfycod(){
if($this->cpage > $this->pageoffset){
$this->start = $this->cpage - $this->pageoffset;
$this->end = $this->total_page > $this->cpage + $this->pageoffset ? $this->cpage + $this->pageoffset : $this->total_page;
}else{
$this->start = 1;
$this->end = $this->total_page > $this->showpage ? $this->showpage : $this->total_page;
}
if($this->cpage + $this->pageoffset > $this->total_page){
$this->start = $this->start - ($this->cpage + $this->pageoffset - $this->end);
}
for($i=$this->start;$i<=$this->end;$i++){
$this->fycod[] = $i;
}
return $this->fycod;
}
}