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实现的后台表格分页功能。分享给大家供大家参考,具体如下: <?php //init.php $conn = mysqli_connect('...

利用swoole+redis实现股票和区块链服务

本文主要给大家介绍了关于swoole+redis实现股票和区块链服务的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。 PHP 的redis扩展是阻塞式 IO...

php排序算法(冒泡排序,快速排序)

冒泡排序实现原理 ① 首先将所有待排序的数字放入工作列表中。② 从列表的第一个数字到倒数第二个数字,逐个检查:若某一位上的数字大于他的下一位,则将它与它的下一位交换。 ③ 重复步骤②,直...

php 利用socket发送HTTP请求(GET,POST)

  今天给大家带来的是如何利用socket发送GET,POST请求。我借用燕十八老师封装好的一个Http类给进行说明。   在日常编程中相信很多人和我一样大部分时间是利用浏览器向服务器提...

PHP字符转义相关函数小结(php下的转义字符串)

文章中有不正确的或者说辞不清的地方,麻烦大家指出了~~~与PHP字符串转义相关的配置和函数如下: 1.magic_quotes_runtime 2.magic_quotes_gpc 3....