php分页代码 页数太多,php google或baidu分页代码
php實(shí)現(xiàn)google與baidu的分頁代碼,需要的朋友可以參考下。
/**
作者:瀟湘博客
時(shí)間:
2009-11-26
php技術(shù)群:
37304662
使用方法:
include_once'Pager.class.php';
$pager=new Pager();
if(isset($_GET['page']))
$pager->setCurrentPage($_GET['page']);
else
$pager->setCurrentPage(1);
$pager->setRecorbTotal(1000);
$pager->setBaseUri("page.php?");
echo $pager->execute();
**/
class Pager{
/**
*int總頁數(shù)
**/
protected $pageTotal;
/**
*int上一頁
**/
protected $previous;
/**
*int下一頁
**/
protected $next;
/**
*int中間頁起始序號
**/
protected $startPage;
/**
*int中間頁終止序號
**/
protected $endPage;
/**
*int記錄總數(shù)
**/
protected $recorbTotal;
/**
*int每頁顯示記錄數(shù)
**/
protected $pageSize;
/**
*int當(dāng)前顯示頁
**/
protected $currentPage;
/**
*string基url地址
**/
protected $baseUri;
/**
*@returnstring獲取基url地址
*/
public function getBaseUri(){
return$this->baseUri;
}
/**
*@returnint獲取當(dāng)前顯示頁
*/
public function getCurrentPage(){
return $this->currentPage;
}
/**
*@returnint獲取每頁顯示記錄數(shù)
*/
public function getPageSize(){
return $this->pageSize;
}
/**
*@returnint獲取記錄總數(shù)
*/
public function getRecorbTotal(){
return$this->recorbTotal;
}
/**
*@paramstring$baseUri設(shè)置基url地址
*/
public function setBaseUri($baseUri){
$this->baseUri=$baseUri;
}
/**
*@paramint$currentPage設(shè)置當(dāng)前顯示頁
*/
public function setCurrentPage($currentPage){
$this->currentPage=$currentPage;
}
/**
*@paramint$pageSize設(shè)置每頁顯示記錄數(shù)
*/
public function setPageSize($pageSize){
$this->pageSize=$pageSize;
}
/**
*@paramint$recorbTotal設(shè)置獲取記錄總數(shù)
*/
public function setRecorbTotal($recorbTotal){
$this->recorbTotal=$recorbTotal;
}
/**
*構(gòu)造函數(shù)
**/
public function __construct()
{
$this->pageTotal=0;
$this->previous=0;
$this->next=0;
$this->startPage=0;
$this->endPage=0;
$this->pageSize=20;
$this->currentPage=0;
}
/**
*分頁算法
**/
private function arithmetic(){
if($this->currentPage<1)
$this->currentPage=1;
$this->pageTotal=floor($this->recorbTotal/$this->pageSize)+($this->recorbTotal%$this->pageSize>0?1:0);
if($this->currentPage>1&&$this->currentPage>$this->pageTotal)
header('location:'.$this->baseUri.'page='.$this->pageTotal);
$this->next=$this->currentPage+1;
$this->previous=$this->currentPage-1;
$this->startPage=($this->currentPage+5)>$this->pageTotal?$this->pageTotal-10:$this->currentPage-5;
$this->endPage=$this->currentPage<5?11:$this->currentPage+5;
if($this->startPage<1)
$this->startPage=1;
if($this->pageTotalendPage)
$this->endPage=$this->pageTotal;
}
/**
*分頁樣式
**/
protected function pageStyle(){
$result="共".$this->pageTotal."頁";
if($this->currentPage>1)
$result.="baseUri."page=1\">第1頁 baseUri."page=$this->previous\">前一頁";
else
$result.="第1頁 ";
for($i=$this->startPage;$i<=$this->endPage;$i++){
if($this->currentPage==$i)
$result.="$i";
else
$result.=" baseUri."page=$i\">$i ";
}
if($this->currentPage!=$this->pageTotal){
$result.="baseUri."page=$this->next\">后一頁 ";
$result.="baseUri."page=$this->pageTotal\">最后1頁";
}else{
$result.="最后1頁 ";
}
return $result;
}
/**
*執(zhí)行分頁
**/
public function execute(){
if($this->baseUri!=""&&$this->recorbTotal==0)
return"";
$this->arithmetic();
return $this->pageStyle();
}
}
?>
總結(jié)
以上是生活随笔為你收集整理的php分页代码 页数太多,php google或baidu分页代码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 华为汽车领域新专利公布,可根据用户心率控
- 下一篇: 电子商务seo是什么(B2B电子商务平台