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;
}
}

相关文章

Ubuntu 16.04下安装PHP 7过程详解

前言 最近由于换了硬盘重装了(升级)系统到Ubuntu16.04之后,开发环境也要重新安装,其实16.04源里面默认的PHP版本就是7.x,但是有个问题就是没有OCI扩展,有项目需要使用...

php通过function_exists检测函数是否存在的方法

本文实例讲述了php通过function_exists检测函数是否存在的方法。分享给大家供大家参考。具体分析如下: php中可以通过function_exists()函数检测另外一个函数...

PHP缓存工具XCache安装与使用方法详解

本文实例讲述了PHP缓存工具XCache安装与使用方法。分享给大家供大家参考,具体如下: XCache是另外一种在PHP中使用的Opcode缓存工具。像APC一样,XCache在共享内存...

php实现读取手机客户端浏览器的类

本文实例讲述了php实现读取手机客户端浏览器的类。分享给大家供大家参考。具体分析如下: 这里介绍的手机信息函数类有取手机号码,浏览器报头信息,取得手机类型,取得手机IP等功能。 复制代码...

常用的php ADODB使用方法集锦

复制代码 代码如下:<?php        //定义数据库变量   ...