php相当简单的分页类

yipeiwu_com5年前PHP代码库
class Helper_Page{

/** 总信息数 */
var $infoCount;
/** 总页数 */
var $pageCount;
/** 每页显示条数 */
var $items;
/** 当前页码 */
var $pageNo;
/** 查询的起始位置 */
var $startPos;
/** 下一页 */
var $nextPageNo;
/** 上一页 */
var $prevPageNo;

function Helper_Page($infoCount, $items, $pageNo)
{
$this->infoCount = $infoCount;
$this->items = $items;
$this->pageNo = $pageNo;
$this->pageCount = $this->GetPageCount();
$this->AdjustPageNo();
$this->startPos = $this->GetStartPos();
}
function AdjustPageNo()
{
if($this->pageNo == '' || $this->pageNo < 1)
$this->pageNo = 1;
if ($this->pageNo > $this->pageCount)
$this->pageNo = $this->pageCount;
}
/**
* 下一页
*/
function GoToNextPage()
{
$nextPageNo = $this->pageNo + 1;
if ($nextPageNo > $this->pageCount)
{
$this->nextPageNo = $this->pageCount;
return false;
}
$this->nextPageNo = $nextPageNo;
return true;
}
/**
* 上一页
*/
function GotoPrevPage()
{
$prevPageNo = $this->pageNo - 1;
if ($prevPageNo < 1)
{
$this->prevPageNo = 1;
return false;
}
$this->prevPageNo = $prevPageNo;
return true;
}
function GetPageCount()
{
return ceil($this->infoCount / $this->items);
}
function GetStartPos()
{
return ($this->pageNo - 1) * $this->items;
}
}

相关文章

PHP文件操作实例总结【文件上传、下载、分页】

PHP文件操作实例总结【文件上传、下载、分页】

本文实例讲述了PHP文件操作。分享给大家供大家参考,具体如下: 1、文件上传 上传域: input type="file" 普通文本框(text、password、textarea、r...

PHP字符转义相关函数小结(php下的转义字符串)

文章中有不正确的或者说辞不清的地方,麻烦大家指出了~~~与PHP字符串转义相关的配置和函数如下: 1.magic_quotes_runtime 2.magic_quotes_gpc 3....

php生成HTML文件的类方法

目的 用PHP生成HTML文档, 支持标签嵌套缩进, 支持标签自定义属性 起因 这个东西确实也是心血来潮写的, 本来打算是输出HTML片段用的, 但后来就干脆写成了一个可以输出完整HT...

php自动更新版权信息显示的方法

本文实例讲述了php自动更新版权信息显示的方法。分享给大家供大家参考。具体分析如下: 我们一般会在页面下方输出版权信息,包含年份信息,每年都要修改,这段简单的代码帮你解决这个问题,自动更...

php导出生成word的方法

本文实例讲述了php导出生成word的方法。分享给大家供大家参考,具体如下: PHP导出word (1)首先,预览html页面,示例化对象,定义要导出的数据 (2)点击下载页面,给id传...