软讯网络 > 网站建设 > PHP > 自己写的个php分页类
【标 题】:自己写的个php分页类
【关键字】:
php
【来 源】:http://www.cublog.cn/u/14585/showart.php?id=158211
自己写的个php分页类
<?php
/******************
*php分页类,适合设计到分页的程序
*作者:痞子狗
*2006-8-20
******************/
class class_div_page
{
private $total_page_size;//总记录数
private $page_size;//每页记录数
private $total_page;//总页数
private $current_url;//当前url
public function init_data($total_page_size,$page_size)
{
$this->total_page_size=($total_page_size>=0)?intval($total_page_size):1;
$this->page_size=($page_size>0)?intval($page_size):intval($total_page_size);
}
public function get_total_page()
{
if($this->total_page_size<=$this->page_size)
{
$this->total_page=1;
}
else
{
if($this->total_page_size%$this->page_size)
{
$this->total_page=(int)($this->total_page_size/$this->page_size)+1;
}
else
{
$this->total_page=$this->total_page_size/$this->page_size;
}
}
return $this->total_page;//根据用户需要可返回总页数
}
public function get_current_url($start_url,$current_page=1)//$start_url="xxxx.php?xxx="这类形式,$current_page即为需要传递的显示页号
{
$current_page=(intval($current_page)>=1)?intval($current_page):1;
$this->get_total_page();
if($this->total_page==1)
{
$this->current_url="";
}
else
{
if($current_page<=$this->total_page&&$current_page>0)
{
if($current_page==1)
{
$current_page+=1;
$this->current_url="<a href=\"".$start_url.$current_page."\">"."下一页</a>";
}
else if($current_page==$this->total_page)
{
$current_page-=1;
$this->current_url="<a href=\"".$start_url.$current_page."\">"."上一页</a>";
}
else
{
$prev_page=$current_page-1;
$next_page=$current_page+1;
$this->current_url="<a href=\"".$start_url.$prev_page."\">"."上一页</a>"." "."<a href=\"".$start_url.$next_page."\">"."下一页</a>";
}
}
else
{
$this->current_url=$this->get_current_url($start_url,$this->total_page);
}
}
return $this->current_url;
}
}
?>
我根据网络上分页说明,自己做了个分页类,没有设计数据库操作。只是纯粹根据数据记录分页。