/************************************************************************************ * Perfect pagination class, can customize the pagination (than Gao teacher's perfect Ha, O (∩_∩) o haha ~) * ************************************************************************************ * Copyright (C) 2011-2012 Beihai love letter-A programmer's blog, and All rights reserved. * * * ********************************************************************************** * $Author: Beihai love Letter (hackmyth@163.com) $ * * $Date: 2011-07-18 10:00:00 $ * * **********************************************************************************/ Class page{
Private $total; Total number of data bars Private $listRows; Show number of bars per page Private $limit; Limit number of bars Private $pageNum; Total pages Private $page; Current page Private $config =array (' head ' = "record", "Prev" and "prev", "Next" = "Next", "first" = "Home", "last" and "End");
/** * Construction method, you can set the properties of the paging class * @param int $total Calculate the total number of records for pagination * @param int $listRows Optional, default number of records to display per page * */ Public function __construct ($total, $listRows =10) {
$this->total= $total; $this->listrows= $listRows; $this->pagenum=ceil ($this->total/$this->listrows); Get Total Pages if ($_get[' page ']> $this->pagenum) {//Prevent over-bounds $_get[' page ']= $this->pagenum; } $this->page=!empty ($_get[' page ')? $_get[' page ']: "1"; Current page $this->limit= $this->setpage (); Page out formula } Public Function __get ($args) {
if ($args = = ' limit ') {//filter illegal request return $this->limit; } return null; } Calculate a page-out formula Private Function Setpage () { Return "Limit". ($this->page-1) * $this->listrows. ",". $this->listrows;
} Previous page Private Function prev () { Return "page-1)." > ". $this->config[' prev ')."; }
Next page Private function Next () { Return "page+1)." > ". $this->config[' next ')."; } Home Private Function First () { Return "". $this->config[' first ']. ""; } Last Private Function Last () { Return "Pagenum)." > ". $this->config[' last ']."; } List of pages
Private Function PageList () { $lists. = '; for ($i =1; $i < $this->pagenum; $i +) { $lists. = "$i"; } return $lists; } Public Function Fpage ($display =array (1,2,3,4,5)) {
$html [1]=]. $this->total. $this->config[' head '; $html [2]= $this->prev (); Previous page $html [3]= $this->next (); Next page $html [4]= $this->first (); Home $html [5]= $this->last (); Last $html [6]= $this->pagelist (); List $fpage = "; foreach ($display as $index) {
$fpage. = $html [$index]; } return $fpage; }
}
|