当前位置: 首页 > 图文教程 > 网络编程 > PHP > php分页类

PHP
PHP6 安装方法
PHP中的ob_start用法详解
学习php遇到的主要问题及解决办法
PHP知识:正则表达式中特殊字符的说明
PHP系列教程:《PHP设计模式介绍》 导言
PHP系列教程:设计模式介绍Ⅰ编程惯用法
PHP系列教程:设计模式介绍Ⅱ值对象模式
PHP系列教程:设计模式介绍Ⅲ工厂模式
PHP系列教程:设计模式介绍Ⅳ单件模式
PHP系列教程:设计模式介绍Ⅴ注册模式
PHP系列教程:设计模式介绍Ⅵ伪对象模式
PHP系列教程:设计模式介绍Ⅶ策略模式
PHP系列教程:设计模式介绍Ⅷ迭代器模式
PHP系列教程:设计模式介绍Ⅸ观测模式
PHP系列教程:设计模式介绍Ⅸ规范模式
PHP教程:自动适应范围的页码分页程序
SQL函数:CONCAT_WS和LENGTH
PHP:招PHP高级工程师的面试题
美化/etc/my.cnf文件
PHP注释查看器

PHP 中的 php分页类


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 60 ::
收藏到网摘: n/a

<?php
//
// +----------------------------------------------------------------------+
// | 分页类                                |
// +----------------------------------------------------------------------+
// | Copyright (c) 2001 NetFish Software                 |
// |                                   |
// | Author: whxbb([email protected])                    |
// +----------------------------------------------------------------------+
//
// $Id: pager.class.php,v 0.1 2001/8/2 13:18:13 yf Exp $
//
// 禁止直接访问该页面
if (basename($HTTP_SERVER_VARS['PHP_SELF']) == "pager.class.php") {
   header("HTTP/1.0 404 Not Found");
}
/**
* 分页类
* Purpose
* 分页
*
* @author : whxbb([email protected])
* @version : 0.1
* @date  : 2001/8/2
*/
class Pager
{
   /** 总信息数 */
   var $infoCount;
   /** 总页数 */
   var $pageCount;
   /** 每页显示条数 */
   var $items;
   /** 当前页码 */
   var $pageNo;
   /** 查询的起始位置 */
   var $startPos;
   var $nextPageNo;
   var $prevPageNo;
   
   function Pager($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;
   }
}
?>