`
lizhiqiang1
  • 浏览: 13004 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

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

 
阅读更多
写了一个分页类 如果有用的话 大家就拿去用吧
<?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();
?>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics