首页 > 代码库 > 关于分页的类(有点粗糙)
关于分页的类(有点粗糙)
<?php
class page
{
public $tab; //表名
public $row; //数据
public $page; //当前页
public $totalpage; //总页数
public $totalsize; //总条数
public $pageindex; //查找索引
public $pagesize; //每页显示条数
public $lastpage; //上一页
public $nextpage; //下一页
function __construct($tab,$pagesize)
{
mysql_connect("127.0.0.1","root","123456");
mysql_select_db("baonier");
$this->tab=$tab;
$this->pagesize=$pagesize;
$sql="select * from ".$this->tab."";
$query=mysql_query($sql);
echo $this->totalsize=mysql_num_rows($query);
$this->totalpage=ceil($this->totalsize/($this->pagesize-1));
$this->page=isset($_GET[‘page‘])?$_GET[‘page‘]:1;
$this->pageindex=($this->page-1)*$this->pagesize;
$this->lastpage=$this->page-1;
$this->nextpage=$this->page+1;
}
function get_array()
{
$sql="select * from ".$this->tab." limit ".$this->pageindex.",".$this->pagesize."";
$q=mysql_query($sql);
$roww=array();
while($rows=mysql_fetch_array($q))
{
$roww[]=$rows;
}
$this->row=$roww;
return $this->row;
}
function get_page()
{
if($this->lastpage<1)
{
$this->lastpage=1;
}
if($this->nextpage>$this->totalpage)
{
$this->nextpage=$this->totalpage;
}
$div="<a href=http://www.mamicode.com/"?page=".$this->lastpage." \">上一页</a><a href=http://www.mamicode.com/"?page=".$this->nextpage."\">下一页</a>";
return $div;
}
}
?>
关于分页的类(有点粗糙)