以前学习时做的,现在也经常用到~~感觉还可以。只是有时候不太方便~~比如做搜索的时候~~有些麻烦~~
呵……其实还是蛮不错的~~
<?php
class Ipagination
{
var $sqlstr; //SQL语句;
var $totalpages; //当前页数;
var $pagesize; //每页显示记录数;
var $totalrecord; //总记录数;
var $getpage; //返回的页;
var $nextpage; //下一页;
var $pervpage; //前一页;
var $result; //记录集;
var $page; //当前页数;
//构造函数
function Ipagination()
{
$this->pagesize = 10;
$this->getpage = 1;
}
function set_pagesize($get_pagesize)
{
$this->pagesize = $get_pagesize;
}
function set_page($get_page)
{
$this->getpage = $get_page;
}
function set_sql($get_sqlstr)
{
$this->sqlstr = $get_sqlstr;
}
function check_getpage($page)
{
if(!(eregi("[0-9]",$page)))
{
$page = 1;
}
if($page <= 1)
{
return (1);
}
if($page > $this->totalpages)
{
return ($this->totalpages);
}
return ($page);
}
function show()
{
$this->totalrecord = mysql_num_rows(mysql_query($this->sqlstr));
$this->totalpages = ceil($this->totalrecord / $this->pagesize);
$this->getpage = $this->check_getpage($this->getpage);
$this->nextpage = $this->check_getpage($this->getpage + 1);
$this->prevpage = $this->check_getpage($this->getpage-1);
$this->result = mysql_query($this->sqlstr." limit ".($this->getpage - 1) * $this->pagesize .", ". $this->pagesize);
}
function nopage()
{
$this->showerror();
}
function showerror()
{
echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\"><tr width=\"100%\"><td>";
echo "<p align=\"center\">暂时没有记录!</p>";
echo "</td></tr></table>";
}
function showpage($get_path) {
if ($this->totalpages == 0) {
$this->nopage();
}
else {
echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\"><tr width=\"100%\"><td align=\"center\">";
$nbsp=" ";
if ($this->getpage == 1) {
echo "第一页".$nbsp."上一页".$nbsp;
}
else {
echo "<a href=\"$get_path?page=1\">第一页</a>$nbsp<a href=\"$get_path?page=$this->prevpage\">上一页</a>$nbsp";
}
if ($this->getpage == $this->totalpages) {
echo "下一页".$nbsp."最后页".$nbsp;
}
else {
echo "<a href=\"$get_path?page=$this->nextpage\">下一页</a>".$nbsp."<a href=\"$get_path?page=$this->totalpages\">最后页</a>".$nbsp;
}
echo "共有 <font color=#ff0000><b>".$this->totalrecord."</b></font> 条记录".$nbsp;
echo "<font color=#ff0000><b>$this->getpage</b></font> (当前页)/ <font color=#ff0000><b>$this->totalpages</b></font> (总页数)".$nbsp;
echo "</td></tr></table>";
}
}
}
?>
本文地址:http://com.8s8s.com/it/it25738.htm