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

PHP
PHP学习中遇到的问题,请高手帮忙 - PHPchina
如何获取IIS虚拟目录的绝对路径 - PHPchina
常常说的SQL注入是怎么做的? - PHPchina
怎么对网站的Alexa排名的数据的采集? - PHPchina
遇到一个session丢失的问题。打开含有mediaplayer播放器的页面,会导致session丢失 -
做小偷遇到一个基础问题.请指教 - PHPchina
php5如何连接ACCESS 2003 - PHPchina
帮找下错误 - PHPchina
split 函数的一个问题 - PHPchina
一个全站系统的数据库设计问题,望大家都来帮帮忙 - PHPchina
分享我的PHP配置心得包含MYSQL5乱码解决 - PHPchina
深入浅出分析Linux设备驱动程序中断 (1)(3)
深入浅出分析Linux设备驱动程序中断 (1)(2)
深入浅出分析Linux设备驱动程序中断 (1)
OpenSSH可实现一次性自动管理多台服务器
如何利用程序循环来控制Perl脚本流程
PHP5应用笔记之Cookie实用攻略(上)
从失败中涉取经验 网站设计的十种常见错误
连载1:利用PHP创建由Oracle 驱动的SOAP服务
连载2:利用PHP创建由Oracle 驱动的SOAP服务

PHP 中的 php分页类


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 56 ::
收藏到网摘: 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;
   }
}
?>