<?php <BR>/** <br><br>作者:潇湘博客 <br><br>时间: <BR>2009-11-26 <br><br>php技术群: <BR>37304662 <br><br>使用方法: <BR>include_once'Pager.class.php'; <BR>$pager=new Pager(); <BR>if(isset($_GET['page'])) <BR>$pager->setCurrentPage($_GET['page']); <BR>else <BR>$pager->setCurrentPage(1); <br><br>$pager->setRecorbTotal(1000); <BR>$pager->se<mark style="color:transparent">来4源gaodaimacom搞#代%码*网</mark><code>搞代gaodaima码</code>tBaseUri("page.php?"); <BR>echo $pager->execute(); <br><br>**/ <BR>class Pager{ <BR>/** <BR>*int总页数 <BR>**/ <BR>protected $pageTotal; <BR>/** <BR>*int上一页 <BR>**/ <BR>protected $previous; <BR>/** <BR>*int下一页 <BR>**/ <BR>protected $next; <BR>/** <BR>*int中间页起始序号 <BR>**/ <BR>protected $startPage; <BR>/** <BR>*int中间页终止序号 <BR>**/ <BR>protected $endPage; <BR>/** <BR>*int记录总数 <BR>**/ <BR>protected $recorbTotal; <BR>/** <BR>*int每页显示记录数 <BR>**/ <BR>protected $pageSize; <BR>/** <BR>*int当前显示页 <BR>**/ <BR>protected $currentPage; <BR>/** <BR>*string基url地址 <BR>**/ <BR>protected $baseUri; <br><br>/** <BR>*@returnstring获取基url地址 <BR>*/ <BR>public function getBaseUri(){ <BR>return$this->baseUri; <BR>} <br><br>/** <BR>*@returnint获取当前显示页 <BR>*/ <BR>public function getCurrentPage(){ <BR>return $this->currentPage; <BR>} <br><br>/** <BR>*@returnint获取每页显示记录数 <BR>*/ <BR>public function getPageSize(){ <BR>return $this->pageSize; <BR>} <br><br>/** <BR>*@returnint获取记录总数 <BR>*/ <BR>public function getRecorbTotal(){ <BR>return$this->recorbTotal; <BR>} <br><br>/** <BR>*@paramstring$baseUri设置基url地址 <BR>*/ <BR>public function setBaseUri($baseUri){ <BR>$this->baseUri=$baseUri; <BR>} <br><br>/** <BR>*@paramint$currentPage设置当前显示页 <BR>*/ <BR>public function setCurrentPage($currentPage){ <BR>$this->currentPage=$currentPage; <BR>} <br><br>/** <BR>*@paramint$pageSize设置每页显示记录数 <BR>*/ <BR>public function setPageSize($pageSize){ <BR>$this->pageSize=$pageSize; <BR>} <br><br>/** <BR>*@paramint$recorbTotal设置获取记录总数 <BR>*/ <BR>public function setRecorbTotal($recorbTotal){ <BR>$this->recorbTotal=$recorbTotal; <BR>} <br><br>/** <BR>*构造函数 <BR>**/ <BR>public function __construct() <BR>{ <BR>$this->pageTotal=0; <BR>$this->previous=0; <BR>$this->next=0; <BR>$this->startPage=0; <BR>$this->endPage=0; <br><br>$this->pageSize=20; <BR>$this->currentPage=0; <BR>} <br><br>/** <BR>*分页算法 <BR>**/ <BR>private function arithmetic(){ <BR>if($this->currentPage<1) <BR>$this->currentPage=1; <br><br>$this->pageTotal=floor($this->recorbTotal/$this->pageSize)+($this->recorbTotal%$this->pageSize>0?1:0); <br><br>if($this->currentPage>1&&$this->currentPage>$this->pageTotal) <BR>header('location:'.$this->baseUri.'page='.$this->pageTotal); <br><br>$this->next=$this->currentPage+1; <BR>$this->previous=$this->currentPage-1; <br><br>$this->startPage=($this->currentPage+5)>$this->pageTotal?$this->pageTotal-10:$this->currentPage-5; <BR>$this->endPage=$this->currentPagecurrentPage+5; <br><br>if($this->startPage<1) <BR>$this->startPage=1; <br><br>if($this->pageTotalendPage) <BR>$this->endPage=$this->pageTotal; <BR>} <br><br>/** <BR>*分页样式 <BR>**/ <br><br><BR>protected function pageStyle(){ <BR>$result="共".$this->pageTotal."页"; <br><br>if($this->currentPage>1) <BR>$result.="baseUri."page=1\"><font style="font-family:webdings">第1页</font> baseUri."page=$this->previous\">前一页</font>"; <BR>else <BR>$result.="<font style="font-family:webdings">第1页</font> <font style="font-family:webdings"></font>"; <br><br>for($i=$this->startPage;$iendPage;$i++){ <BR>if($this->currentPage==$i) <BR>$result.="<font color="#ff0000">$i</font>"; <BR>else <BR>$result.=" baseUri."page=$i\">$i "; <BR>} <br><br>if($this->currentPage!=$this->pageTotal){ <BR>$result.="baseUri."page=$this->next\"><font style="font-family:webdings">后一页</font> "; <BR>$result.="baseUri."page=$this->pageTotal\"><font style="font-family:webdings">最后1页</font>"; <BR>}else{ <BR>$result.="<font style="font-family:webdings">最后1页</font> <font style="font-family:webdings"></font>"; <BR>} <BR>return $result; <BR>} <br><br><br><br>/** <BR>*执行分页 <BR>**/ <BR>public function execute(){ <BR>if($this->baseUri!=""&&$this->recorbTotal==0) <BR>return""; <BR>$this->arithmetic(); <BR>return $this->pageStyle(); <BR>} <BR>} <BR>?><BR>