网站地图    收藏   

主页 > php专栏 > php类库 >

PHP分页类 - php类库

来源:自学PHP网    时间:2014-11-30 12:53 作者: 阅读:次

[导读] ?php 禁止直接访问该页面if(basename($HTTP_SERVER_VARS[ 39;PHP_SELF 39;])==pager class php){ header(HTTP 1 0404NotFound);...

PHP分页类

  1. <?php 
  2. // 禁止直接访问该页面 
  3. if (basename($HTTP_SERVER_VARS['PHP_SELF']) == "pager.class.php") { 
  4.    header("HTTP/1.0 404 Not Found"); 
  5. } 
  6.  
  7. class Pager 
  8. { 
  9.    /** 总信息数 */ 
  10.    var $infoCount; 
  11.    /** 总页数 */ 
  12.    var $pageCount; 
  13.    /** 每页显示条数 */ 
  14.    var $items; 
  15.    /** 当前页码 */ 
  16.    var $pageNo; 
  17.    /** 查询的起始位置 */ 
  18.    var $startPos; 
  19.    var $nextPageNo; 
  20.    var $prevPageNo; 
  21.   
  22.    function Pager($infoCount, $items, $pageNo) 
  23.    { 
  24.      $this->infoCount = $infoCount; 
  25.      $this->items   = $items; 
  26.      $this->pageNo  = $pageNo; 
  27.      $this->pageCount = $this->GetPageCount(); 
  28.      $this->AdjustPageNo(); 
  29.      $this->startPos = $this->GetStartPos(); 
  30.    } 
  31.    function AdjustPageNo() 
  32.    { 
  33.      if($this->pageNo == '' || $this->pageNo < 1) 
  34.        $this->pageNo = 1; 
  35.      if ($this->pageNo > $this->pageCount) 
  36.        $this->pageNo = $this->pageCount; 
  37.    } 
  38.    /** 
  39.    * 下一页 
  40.    */ 
  41.    function GoToNextPage() 
  42.    { 
  43.      $nextPageNo = $this->pageNo 1; 
  44.      if ($nextPageNo > $this->pageCount) 
  45.      { 
  46.        $this->nextPageNo = $this->pageCount; 
  47.        return false; 
  48.      } 
  49.      $this->nextPageNo = $nextPageNo; 
  50.      return true; 
  51.    } 
  52.    /** 
  53.    * 上一页 
  54.    */ 
  55.    function GotoPrevPage() 
  56.    { 
  57.      $prevPageNo = $this->pageNo - 1; 
  58.      if ($prevPageNo < 1) 
  59.      { 
  60.        $this->prevPageNo = 1; 
  61.        return false; 
  62.      } 
  63.      $this->prevPageNo = $prevPageNo; 
  64.      return true; 
  65.    } 
  66.    function GetPageCount() 
  67.    { 
  68.      return ceil($this->infoCount / $this->items); 
  69.    } 
  70.    function GetStartPos() 
  71.    { 
  72.      return ($this->pageNo - 1) * $this->items; 
  73.    } 
  74. } 
  75. ?> 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论