<p> <code><?php<br />//<br />// +----------------------------------------------------------------------+<br />// | 分页类  |<br />// +----------------------------------------------------------------------+<br />// | Copyright (c) 2001 NetFish Software |<br />// | |<br />// | Author: whxbb(<a href="mailto:whxbbh@21cn.com">whxbbh@21cn.com</a>)  |<br />// +----------------------------------------------------------------------+<br />//<br />// $Id: pager.class.php,v 0.1 2001/8/2 13:18:13 yf Exp $<br />//<br />// 禁止直接访问该页面<br />if (basename($HTTP_SERVER_VARS['PHP_SELF']) == "pager.class.php") {<br />
header("HTTP/1.0 404 Not Found");<br />}<br />/**<br />* 分页类<br />* Purpose<br />* 分页<br />*<br />* @author : whxbb(<a href="mailto:whxbb@21cn.com">whxbb@21cn.com</a>)<br />* @version : 0.1<br />* @date : 2001/8/2<br />*/<br />class Pager<br />{<br />
/** 总信息数 */<br />
var $infoCount;<br />
/** 总页数 */<br />
var $pageCount;<br />
/** 每页显示条数 */<br />
var $items;<br />
/** 当前页码 */<br />
var $pageNo;<br />
/** 查询的起始位置 */<br />
var $startPos;<br />
var $nextPageNo;<br />
var $prevPageNo;<br />  <br />
function Pager($infoCount, $items, $pageNo)<br />
{<br />
$this->infoCount = $infoCount;<br />
$this->items  = $items;<br />
$this->pageNo = $pageNo;<br />
$this->pageCount = $this->GetPageCount();<br />
$this->AdjustPageNo();<br />
$this->startPos = $this->GetStartPos();<br />
}<br />
function AdjustPageNo()<br />
{<br />
if($this->pageNo == '' || $this->pageNo < 1)<br />
$this->pageNo = 1;<br />
if ($this->pageNo > $this->pageCount)<br />
$this->pageNo = $this->pageCount;<br />
}<br />
/**<br />  * 下一页<br />  */<br />
function GoToNextPage()<br />
{<br />
$nextPageNo = $this->pageNo + 1;<br />
if ($nextPageNo > $this->pageCount)<br />
{<br />
$this->nextPageNo = $this->pageCount;<br />
return false;<br />
}<br />
$this->nextPageNo = $nextPageNo;<br />
return true;<br />
}<br />
/**<br />  * 上一页<br />  */<br />
function GotoPrevPage()<br />
{<br />
$prevPageNo = $this->pageNo - 1;<br />
if ($prevPageNo < 1)<br />
{<br />
$this->prevPageNo = 1;<br />
return false;<br />
}<br />
$this->prevPageNo = $prevPageNo;<br />
return true;<br />
}<br />
function GetPageCount()<br />
{<br />
return ceil($this->infoCount / $this->items);<br />
}<br />
function GetStartPos()<br />
{<br />
return ($this->pageNo - 1) * $this->items;<br />
}<br />}<br />?></code></p>