自己写的分页类

length = $length;
$this->stipulation = $stipulation;
$this->table = $table;
}
function calculateTotal() {
$sql = "select * from {$this->table} where 1=1";
include_once('class_db.php');
$db = new db;
$query = $db->query($sql);
$this->total = $db->getNum($query);
}
//输出记录总数
function getTotal() {
$this->calculateTotal();
return $this->total;
}
function calculatePages() {
$this->pages = ceil($this->total/$this->length);
}
//输出总页数
function getPages() {
$this->calculatePages();
return $this->pages;
}

function current($num='') {
$nowStart = $num ? $num : self::$offset*$this->length;
$sql = "select * from {$this->table} where 1=1 ORDER BY {$this->stipulation} DESC limit ".$nowStart.",".$this->length;
include_once('class_db.php');
$db = new db;
$query = $db->query($sql);
while($result = $db->assoc($query)) {
$this->content[] = $result;
}
}
//输出当前需显示的记录
function getPage($num='') {
$this->current($num);
return $this->content;
}
//输出当前页码
static function getNowPageNum() {
return self::$offset+1;
}
//输出上一页
function getPrevious() {
$dir = $PHP_SELF;
$offset=self::$offset-1;
$dir = $offset>=0 ? $dir."?offset=$offset" : '';
return $dir;
}
//输出下一页
function getNext() {
$dir = $PHP_SELF;
$offset=self::$offset+1;
if($offset<$this->getPages()) {
$dir = $dir."?offset=".$offset;
return $dir;
} else {
$dir = $dir."?offset=".($this->pages-1);
return $dir;
}
}
}
?>

发表评论

返回顶部