[php]代码库
@charset "utf-8";
*{padding:0;margin:0;}
.page {
font-size: 14px;
text-align:center
}
.page ul{list-style-type:none;display:table;margin-left:auto;margin-right:auto}
.page ul li{min-width:20px;padding:5px;margin-left:3px;border:1px solid #CCC;text-align:center;float:left;*float:none;*display:inline;*zoom:1;}
.page .select{font-weight:bold;color:#000;font-size:14px;background-color:#F5F5F5;}
.page li a{text-decoration:none;color:#333}
.page .gray{color:#808080}
<?php
class page{
public $pagesize;
public $pagecount;
public $currentpage;
public $pageurl;
public $totalpage;
function __construct($pagesize=15,$pagecount=0,$currentpage=1,$pageurl){
$this->pagesize = $pagesize;
$this->pagecount = $pagecount;
$this->currentpage = $currentpage;
$this->pageurl = $pageurl;
$this->totalpage = ceil($this->pagecount / $this->pagesize);
}
function showpage(){
$pagelink = "";
$pagelink .= "<div class='page'><ul>";
//判断是否为第一页
if($this->currentpage==1){
$pagelink .= "<li class='gray'>最前页</li>";
}else{
$pagelink .= "<li><a href=\\"$this->pageurl"."p=1\\">最前页</a></li>";
}
if($this->currentpage > 1 && $this->totalpage > 1){
$prepage = $this->currentpage -1;
$pagelink .= "<li><a href=\\"$this->pageurl"."p=".$prepage."\\">上一页</a></li>";
}else{
$pagelink .= "<li class='gray'>上一页</li>";
}
//判断页总数
if($this->totalpage <= 11){
$frompage = 1;
$topage = $this->totalpage;
}else{
if($this->currentpage <= 6){
$frompage = 1;
$topage = 11;
}
else if($this->currentpage > 6 && $this->totalpage - 6 > $this->currentpage){
$frompage = $this->currentpage - 5;
$topage = $this->currentpage + 5;
}else{
$frompage = $this->totalpage - 11;
$topage = $this->totalpage;
}
}
for($i=$frompage;$i<=$topage;$i++){
if($i==$this->currentpage){
$pagelink .= "<li class=\\"select\\">$i</li>";
}else{
$pagelink .= "<li><a href=\\"".$this->pageurl."p=$i\\">$i</a></li>";
}
}
//最后页面判断
if($this->currentpage < $this->totalpage){
$nextpage = $this->currentpage + 1;
$pagelink .= "<li><a href=\\"$this->pageurl"."p=".$nextpage."\\">下一页</a></li>";
}else{
$pagelink .= "<li class='gray'>下一页</li>";
}
if($this->currentpage==$this->totalpage){
$pagelink .= "<li class='gray'>最后页</li>";
}else{
$pagelink .= "<li class='gray'><a href=\\"$this->pageurl"."p=$this->totalpage\\">最后页</a></li>";
}
$pagelink .="</ul>";
$pagelink .="<br clear=\\"left\\" />";
$pagelink .="</div>";
return $pagelink;
}
}
?>