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求今天、昨天、明天时间戳的简单实现方法。分享给大家供大家参考,具体如下: echo strtotime('now'),'<br>';//现在 echo...

php表单转换textarea换行符的方法

下面是我对这个问题的解决过程,最后算是完全搞懂了,真是阴沟里险些翻船 1.必须知道textarea中的换行符是 \n  (个人检测发现按回车键是\n,好像在linux下是\r...

自制PHP框架之设计模式

为什么要使用设计模式? 设计模式,我的理解是为了达到“可复用”这个目标,而设计的一套相互协作的类。 感兴趣的读者可以阅读《Design Patterns: Elements of Reu...

解决安装WampServer时提示缺少msvcr110.dll文件的问题

解决安装WampServer时提示缺少msvcr110.dll文件的问题

今天开始学习PHP,对于初学者来说,我们一定希望从简单的开始,所以,从集成环境非常好的WampServer的安装开始. 1、下载WampServer安装程序,安装完毕后会出现一个错误.如...

PHP提示Notice: Undefined variable的解决办法

PHP默认配置会报这个错误,我的PHP版本是5.2.13,存在这个问题: Notice: Undefined variable 这就是将警告在页面上打印出来,虽然这是有利于暴露问题,但实...