<?
#54683213468435132138454312.21354165
#Explain: 类似百度的分页类
#Author : 侏罗记
#Date :2007-12-19
#MAIL :
[email protected]
#54683213468435132138454312.21354165
class page
{
private $number; //每页显示信息条数
private $ossSet; //偏移量
private $msgNum; //信息总条数
private $url; //传出url
public function __construct($number,$offSet,$msgNum,$url)
{
$this->number = $number;
$this->offSet = $offSet;
$this->msgNum = $msgNum;
$this->url = $url;
}
public function pages()
{
//页码偏移量
$pageSet = '9';
if(empty($this->offSet))
{
$offSet = '0';
}
// 计算总页数
$pageNum = intval($this->msgNum/$this->number);
//计算当前页码
$page = ($this->offSet/$this->number) > '0' ? ($this->offSet/$this->number) : '1';
// 计算起始页码
if($page < '11')
{
$startPageNum = '1';
}
else
{
$startPageNum = $page - $pageSet;
}
//计算结束页码
$endPageNum = $page+$pageSet;
if($endPageNum > $pageNum)
{
$endPageNum = $pageNum;
}
$pos = $this->offSet - $this->number;
$next = $this->offSet + $this->number;
if($pos < '0')
{
$pos = '0';
}
if($next > $this->msgNum)
{
$next = $this->msgNum;
}
//上一页
$upPage = "<a href=".$this->url."?page=".$pos.">上一页</a>";
//下一页
$nextPage = "<a href=".$this->url."?page=".$next.">下一页</a>";
//构成页码 123....789
$string = "";
for($f=$startPageNum;$f<=$endPageNum;$f++)
{
if($f == $page)
{
$string .= $f;
}
else
{
$string .= "<a href=".$this->url.'?page='.($f*$this->number).">[".$f."]</a>";
}
}
//输出页码
echo $upPage.$string.$nextPage;
}
}
/************使用方法*************/
$offSet = $_GET['page'];
$page = new page(10,$offSet,200,'page_class.php');
$page->pages();
?>