控制分页列表宽度的分页类

写了一个分页类 如果有用的话 大家就拿去用吧

<?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();
?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值