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抽象类和接口用法。分享给大家供大家参考,具体如下: 前言 对于oop,估计大多数人并不陌生。有些人除PHP外也学习不少其他语言,会发现php的不同之处,可能语法极其丑...

PHP中file_put_contents追加和换行的实现方法

在PHP的一些应用中需要写日志或者记录一些信息,这样的话。可以使用fopen(),fwrite()以及 fclose()这些进行操作。也可以简单的使用file_get_contents(...

php实现获取近几日、月时间示例

本文实例讲述了php实现获取近几日、月时间。分享给大家供大家参考,具体如下: <?php date_default_timezone_set('Asia/Shangha...

PHP项目开发中最常用的自定义函数整理

<?php //alert提示 function alert($msg){ echo "<script>alert('$msg');</script>";...

PHP Swoole异步Redis客户端实现方法示例

PHP Swoole异步Redis客户端实现方法示例

本文实例讲述了PHP Swoole异步Redis客户端实现方法。分享给大家供大家参考,具体如下: 使用版本:1.8.0及以上 使用条件: 1.开启async-redis php --...