一个很简单的PHP分页类
<?php
class page
{
public $page; public $num;
public $result; public $tot;
public $total; public $pagenum;
public $offset; public $info;
public $it; public $show;
public $style; public $property;
public function set_page() //设置第几页
{
$this->page=isset($_GET['page'])?intval($_GET['page']):1;
}
public function set_table($tab) //设置哪张表
{
$this->table=$tab;
$this->set_page();
}
public function set_num($n) //每页显示多少条记录
{
$this->num=$n;
}
public function mysql_conn()
{
$this->conn=mysql_connect("localhost","root","password");
mysql_select_db("db_name");
}
public function mysql_total() //计算出表中记录的总数
{
$this->mysql_conn();
$this->result=mysql_query("select COUNT(*) from ".$this->table);
$this->tot=mysql_fetch_array($this->result);
$this->total=$this->tot['0'];
$this->pagenum=ceil($this->total/$this->num);
//echo "mysql_total".$this->pagenum;
}
public function mysql_show($prop) //全部显示出哪些字段
{
$this->mysql_total();
$this->property=$prop;
if($this->page>$this->pagenum || $this->page == 0){
echo "Error : Can Not Found The page.";
exit;
}
$this->offset=($this->page-1)*$this->num;
$this->info=mysql_query("select * from ".$this->table." limit ".$this->offset.",".$this->num);
while($this->it=mysql_fetch_array($this->info))
{
echo $this->it[$this->property]."<br/>";
}
$this->mysql_page();
}
public function mysql_page() //页码
{
global $search;
for($i=1;$i<=$this->pagenum;$i++){
if($i==1)
{echo " ";}
$this->show=($i!=$this->page)?"[<a href='".$_SERVER['PHP_SELF']."?search=".$search."&page=".$i."'>$i</a>]":"<b>$i</b>";
echo $this->show." ";
}
}
}
$test = new page();
$test->set_table("table_name");
$test->set_num(2);
$test->mysql_show("name");
?>
<?php
class page
{
public $page; public $num;
public $result; public $tot;
public $total; public $pagenum;
public $offset; public $info;
public $it; public $show;
public $style; public $property;
public function set_page() //设置第几页
{
$this->page=isset($_GET['page'])?intval($_GET['page']):1;
}
public function set_table($tab) //设置哪张表
{
$this->table=$tab;
$this->set_page();
}
public function set_num($n) //每页显示多少条记录
{
$this->num=$n;
}
public function mysql_conn()
{
$this->conn=mysql_connect("localhost","root","password");
mysql_select_db("db_name");
}
public function mysql_total() //计算出表中记录的总数
{
$this->mysql_conn();
$this->result=mysql_query("select COUNT(*) from ".$this->table);
$this->tot=mysql_fetch_array($this->result);
$this->total=$this->tot['0'];
$this->pagenum=ceil($this->total/$this->num);
//echo "mysql_total".$this->pagenum;
}
public function mysql_show($prop) //全部显示出哪些字段
{
$this->mysql_total();
$this->property=$prop;
if($this->page>$this->pagenum || $this->page == 0){
echo "Error : Can Not Found The page.";
exit;
}
$this->offset=($this->page-1)*$this->num;
$this->info=mysql_query("select * from ".$this->table." limit ".$this->offset.",".$this->num);
while($this->it=mysql_fetch_array($this->info))
{
echo $this->it[$this->property]."<br/>";
}
$this->mysql_page();
}
public function mysql_page() //页码
{
global $search;
for($i=1;$i<=$this->pagenum;$i++){
if($i==1)
{echo " ";}
$this->show=($i!=$this->page)?"[<a href='".$_SERVER['PHP_SELF']."?search=".$search."&page=".$i."'>$i</a>]":"<b>$i</b>";
echo $this->show." ";
}
}
}
$test = new page();
$test->set_table("table_name");
$test->set_num(2);
$test->mysql_show("name");
?>
作者:noel@淘宝网女装新款秋装连衣裙裤子外套上衣_2012时尚女装新款 Ecmall二次开发-PHP技术
地址:http://www.laohucheng.com/post/304/
版权所有©转载时必须以链接形式注明作者和原始出处及本声明!
face=webdings face=wingdings
jQuery 源码+实例+注释 [新手提高速成]
2009
13:12
698
0


