<?php
class Page
{
var $table;//表名
var $counts;//总条数
var $pagesize;//每页的条数
var $pages;//总页数
var $page;//当前页
var $first;//第一个
var $uppage;//上一页
var $downpage;//下一页
function __construct($tables,$size)
{
$this->table=$tables;
$this->pagesize=$size;
$sql="select * from ".$this->table." ";
$query=mysql_query($sql);
$row=mysql_num_rows($query);
$this->counts=$row;
$this->pages=ceil($this->counts/$this->pagesize);
$this->page=isset($_GET[‘page‘])?$_GET[‘page‘]:1;
$this->first=($this->page-1)*$this->pagesize;
$this->uppage=$this->page-1;
$this->downpage=$this->page+1;
}
function get_rows()
{
$sql2="select * from ".$this->table." limit ".$this->first.",".$this->pagesize."";
$query2=mysql_query($sql2);
$data=array();
while($rows=mysql_fetch_array($query2))
{
$data[]=$rows;
}
return $data;
}
function show_item()
{
if($this->uppage<1)
{
$this->uppage=1;
}
if($this->downpage>$this->pages)
{
$this->downpage=$this->pages;
}
$div="<a href=\"?page=1\">首页</a>
<a href=\"?page=".$this->uppage."\">上一页</a>
<a href=\"?page=".$this->downpage."\">下一页</a>
<a href=\"?page=".$this->pages."\">尾页</a>";
return $div;
}
?>