php分页类
时间:2006-06-23 来源:yanjing5462
实例:
$page = new ShowPage;
$page->PageSize = 20;//每页数
$page->Total = 100;//记录总数
echo $page->ShowLink();
*****/
class ShowPage {
var $PageSize; //每页显示的记录数
var $Total; //记录总数
var $LinkAry; //Url参数数组,对于复合条件查询分页显示情况非常好用
//取得总页数
function PageCount() {
$TotalPage = ceil($this->Total / $this->PageSize);
return $TotalPage;
}
//取得当前页
function PageNum() {
$page = (isset( $_GET['page'])!="") ? $_GET['page'] : $page = 1;
return $page;
}
//查询语句定位指针
function OffSet() {
if ($this->PageNum() > $this->PageCount()) {
//$this->PageNum = $this->PageCount();
$pagemin = max(0,$this->Total - $this->PageSize - 1);
}else if ($this->PageNum() == 1){
$pagemin = 0;
}else {
$pagemin = min($this->Total - 1,$this->PageSize * ($this->PageNum() - 1));
}
return $pagemin . "," . $this->PageSize;
}
//定位首页
function FristPage() {
$Frist = ($this->PageNum() Url($this->LinkAry)."\">首页 ";
return $Frist;
}
//定位上一页
function PrePage() {
$prepage=$this->PageNum() - 1;
$Previous = ($this->PageNum() >= 2) ? " Url($this->LinkAry)."\">上一页 " : "上一页 ";
return $Previous;
}
//定位下一页
function NextPage() {
$nextpage = $this->PageNum() + 1;
$Next = ($this->PageNum() PageCount()-1) ? " Url($this->LinkAry)."\">下一页 " : "下一页 ";
return $Next;
}
//定位最后一页
function LastPage() {
$Last = ($this->PageNum() >= $this->PageCount()) ? "尾页 " : " PageCount().$this->Url($this->LinkAry)."\">尾页 ";
return $Last;
}
//下拉跳转页面
function JumpPage() {
$Jump = " 当前第 ".$this->PageNum()." 页 共 ".$this->PageCount()." 页 跳到 ";
for ($i=1; $iPageCount(); $i++) {
if ($i==$this->PageNum())
$Jump .= "Url($this->LinkAry)."\" selected>$i";
else
$Jump .="Url($this->LinkAry)."\">$i ";
}
$Jump .= " 页";
return $Jump;
}
//URL参数处理
function Url($ary) {
$Linkstr = "";
if (count($ary) > 0) {
foreach ($ary as $key => $val) {
$Linkstr .= "&".$key."=".$val;
}
}
return $Linkstr;
}
//生成导航条
function ShowLink() {
return $this->FristPage().$this->PrePage().$this->NextPage().$this->LastPage().$this->JumpPage();
}
}
?>
相关阅读 更多 +