php相当简单的分页类

yipeiwu_com6年前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快速导入大量数据到数据库的方法 第一种方法:使用insert into 插入,代码如下: $params = array(‘value'=>'50′); set_...

PHP实现的装箱算法示例

本文实例讲述了PHP实现的装箱算法。分享给大家供大家参考,具体如下: 贪婪法是一种不追求最优解,只希望得到较为满意解的方法。贪婪法一般可以快速得到满意的解,因为它省去了为找最优解要穷尽所...

PHP简单获取多个checkbox值的方法

本文实例讲述了PHP简单获取多个checkbox值的方法。分享给大家供大家参考,具体如下: HTML页面: <html> <head> </head...

php+ajax实现带进度条的上传图片功能【附demo源码下载】

php+ajax实现带进度条的上传图片功能【附demo源码下载】

本文实例讲述了php+ajax实现带进度条的上传图片功能。分享给大家供大家参考,具体如下: 运行效果图如下: 代码如下: <?php if(isset($_FILES...

php获得url参数中具有&的值的方法

实际在项目过程中,我们经常会遇到要获取上一页地址的路径。你可以返回上一页使用 复制代码 代码如下: <script>window.history.go(-1);</sc...