ページング・リストの幅を制御するページング・クラス
2691 ワード
ページングクラスを書いたので役に立つならみんなで持って行って使いましょう
<?php
header('Content-Type:text/html; charset=utf-8');
/**
*
* @author lizhiqiang
* @version 1.1
*/
class DataPage{
//
var $PageNo = 1;
//
var $TotalCount = 0;
//
var $PageSize = 0;
//
var $list_len=0;
//
var $page_list="";
//
function __construct($pageno,$totalcount,$list_len,$pagesize)
{
$this->PageNo = $pageno;
$this->TotalCount = $totalcount;
$this->list_len = $list_len;
$this->PageSize = $pagesize;
}
function ShowPage()
{
$pagenext = $this->PageNo+1;
$pagebefore = $this->PageNo-1;
$pagecount = ceil($this->TotalCount/$this->PageSize);
if($this->PageNo!=1)
{
$this->page_list = "<a href='?page=1'> </a>";
$this->page_list .= "<a href='?page=$pagebefore'> </a>";
}
if($this->PageNo!=$pagecount&&$pagecount>0)
{
$this->page_list .= "<a href='?page=$pagenext'> </a>";
$this->page_list .= "<a href='?page=$pagecount'> </a>";
}
//
$total_list = $this->list_len*2+1;
if($this->PageNo >= $total_list)
{
$j = $this->PageNo - $this->list_len;
$total_list = $this->PageNo+$this->list_len;
if($total_list>$pagecount)
{
$total_list = $pagecount;
}
}
else
{
$j=1;
if($total_list>$pagecount)
{
$total_list = $pagecount;
}
}
$toppage = '<ul>';
$footpage = '</ul>';
$num_list=null;
for ($j;$j<=$total_list;$j++)
{
if($this->PageNo == $j)
{
$num_list.="<li><a href='#' class='y'>".$j."</a></li>";
}
else
{
$num_list.="<li><a href='?page=".$j."'>".$j."</a></li>";
}
}
$this->page_list .= $toppage.$num_list.$footpage;
return $this->page_list;
}
}
$_GET['page']!=null ? $page = $_GET['page'] : $page =1;
$datapage = new DataPage($page,500,5,10);
echo $datapage->ShowPage();
?>