首页 > 代码库 > 初出茅庐的分页封装- - -面向对象
初出茅庐的分页封装- - -面向对象
<?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=http://www.mamicode.com/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=http://www.mamicode.com/"?page=1\">首页</a>
<a href=http://www.mamicode.com/"?page=".$this->uppage."\">上一页</a>
<a href=http://www.mamicode.com/"?page=".$this->downpage."\">下一页</a>
<a href=http://www.mamicode.com/"?page=".$this->pages."\">尾页</a>";
return $div;
}
?>
初出茅庐的分页封装- - -面向对象