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中CI操作多个数据库的代码

其实,这不是什么难事,因为刚入手CI,所以还是费了一番周折。好在有手册。 找到数据库配置文件,添加一个新的库的连接信息。$config[XX]。 在控制器里边,     a) $this...

php中return的用法实例分析

本文实例讲述了php中return的用法。分享给大家供大家参考。具体分析如下: 首先,它的意思就是返回;return()是语言结构而不是函数,仅在参数包含表达式时才需要用括号将其括起来。...

php中通过eval实现字符串格式的计算公式

有时候我们对每一种产品都有一个提成公式,而这个计算提成的公式是以字符串格式存在表中的当我们用这个计算公式时,他并不像我们写的:$a=2+3*5;这样简单的能计算出结果,而它是个字符串.所...

PHP赋值的内部是如何跑的详解

PHP赋值的内部是如何跑的详解

前言 在PHP中,一个变量被赋值,内部到底经历了怎样的逻辑判断呢? PHP在内核中是通过zval这个结构体来存储变量的,它的定义在Zend/zend.h文件里 struct _zva...

php设计模式 Factory(工厂模式)

复制代码 代码如下: <?php /** * 工厂方法模式 * * 定义一个用于创建对象的接口,让子类决定将哪一个类实例化,使用一个类的实例化延迟到其子类 */ /* class...