一个php翻页类

王朝php·作者佚名  2008-05-21
窄屏简体版  字體: |||超大  

<?phpclass 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();?>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航