/***
分页类
20080505
***/
require_once('mysql.php');//mysql.php文件在上一篇日志
class page{
private $url;
private $pagesize;
private $sql;
private $getpage;
//参数:sql语句,每页记录数,传递链接(例如"index.php?"或者"index.php?sort=1&"等)
function __construct($sql,$pagesize,$url) {
$this->url = $url;
$this->pagesize = $pagesize;
$this->sql = $sql;
$this->getpage = $_GET["page"];
if(!$this->getpage) {
$this->getpage=1;
}
}
//取记录总数
function getcount() {
return mysql_num_rows(mysql_query($this->sql));
}
//格式化sql语句
function pagesql() {
$nowpage = $this->getpage;
$limitNumber= $this->pagesize;
if($nowpage
$nowpage=1;
}
return $this->sql." limit ".($nowpage-1)*$limitNumber.",".$limitNumber;
}
//显示分页,参数:显示数字链接个数,开始步进的页
function show($page = 5,$offset = 2){
$mpurl = $this->url;
$curr_page = $this->getpage;
$perpage = $this->pagesize;
$num=$this->getcount();//总记录数
$multipage = "";
if ($num > $perpage){
$pages = ceil($num / $perpage);
$from = $curr_page - $offset;
$to = $curr_page + $page - $offset - 1;
if ($page > $pages){
$from = 1;
$to = $pages;
}else{
if ($from
$to = $curr_page + 1-$from;
$from = 1;
if (($to - $from)
$to = $page;
}
}elseif ($to > $pages){
$from = $curr_page - $pages + $to;
$to = $pages;
if (($to - $from)
$from = $pages - $page + 1;
}
}
}
$multipage .="
";
$multipage .= "