VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > PHP >
  • 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. ?> 
  76.  

出处:http://www.phpfensi.com/php/20131210/916.html


相关教程