------------
<?php
class Page{
private $totalpage;
private $stride;
private $currentpage;
//設置總頁數
function setTotalpage($objpage=0){
$this->totalpage=$objpage;
}
//設置當前頁
function setCurrentpage($objpage=1){
$this->currentpage=$objpage;
}
//設置跨度
function setStride($objStride=1){
$this->stride=$objStride;
}
//獲得總頁數
function getTotalpage(){
return $this->totalpage;
}
//獲得跨讀
function getStride($objStride=1){
return $this->stride;
}
//獲取當前頁
function getCurrentpage($objpage=1){
return $this->currentpage;
}
//打印分頁
function Pageprint(){
for($Tmpa=0;$Tmpa<$this->totalpage;$Tmpa++){
if($Tmpa+$this->stride<$this->currentpage){//加了跨度還小于當前頁的不顯示
continue;
}
if($Tmpa+$this->stride==$this->currentpage){//剛好夠跨度的頁數
$p=$this->currentpage-$this->stride-1;
$willprint.="<a href=\"$_SERVER[PHP_SELF]?page=1\"><strong><<</strong></a> <a href=\"$_SERVER[PHP_SELF]?page=$p\"><strong><</strong></a> ";
}
if($Tmpa>$this->currentpage+$this->stride){//大于當前頁+跨度的頁面
break;
}
$willprint.="<a href=\"$_SERVER[PHP_SELF]?page=$Tmpa\"><strong>$Tmpa</strong></a> ";
if($Tmpa==$this->currentpage+$this->stride){//剛好夠跨度的頁數
$p=$this->currentpage+$this->stride+1;
$willprint.="<a href=\"$_SERVER[PHP_SELF]?page=$p\"><strong>></strong></a> <a href=\"$_SERVER[PHP_SELF]?page=$this->totalpage\"><strong>>></strong></a>";
}
}
echo $willprint;
}
}
if(isset($_GET[page])){
$page=$_GET[page];
}else{
$page=1;
}
$CC=new Page();
$CC->setTotalpage(1000);
$CC->setCurrentpage($page);
$CC->setStride(5);
$CC->Pageprint();
?>
延伸閱讀
文章來源于領測軟件測試網 http://www.kjueaiud.com/