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直接修改表内容DataGrid功能实现代码

PHP直接修改表内容DataGrid功能实现代码

由于需要连接Oracle所以从二次开发和页面样式来说个人觉得phpMyDataGrid还是比较好上手。 1. 创建测试数据库和表 create database `guru`;...

详解php的魔术方法__get()和__set()使用介绍

先看看php官方文档的解释: __set() is run when writing data to inaccessible properties. __get() is utiliz...

php中使用exec,system等函数调用系统命令的方法(不建议使用,可导致安全问题)

php的内置函数exec,system都可以调用系统命令(shell命令),当然还有passthru,escapeshellcmd等函数。 在很多时候利用php的exec,system等...

php_screw 1.5:php加密: 安装与使用详解

php文件通常以文本格式存贮在服务器端, 很容易被别人读到源代码, 为了对源代码进行保护, 可以采用对源代码进行加密的方式.要实现该功能需要两部分:一是加密程序,实现对PHP文件的加密....

php使用PDO下exec()函数查询执行后受影响行数的方法

本文实例讲述了php使用PDO下exec()函数查询执行后受影响行数的方法。分享给大家供大家参考,具体如下: exec()方法返回执行后受影响的行数。 语法:int PDO::exec(...