我的分页类

  1. <?PHP   
  2.   
  3. class page   
  4. {   
  5.     var $curPage;    // 当前页   
  6.     var $pageBarNum// 分页条显示页码数   
  7.     var $queryId;    // 数据集   
  8.     var $rsCount;    // 数据数   
  9.     var $pageCount;  // 总页数   
  10.     var $rsOffset;   // 查询偏移量   
  11.     var $urlSuffix;  // URL后缀   
  12.   
  13.     var $startNum;   
  14.     var $endNum;   
  15.     var $prevPage;   
  16.     var $nextPgae;   
  17.   
  18.     // 构造函数   
  19.     // function __construct() {   
  20.     function page($dbTable$curPage$eveNum$pageBarNum$sqlSuffix = '')   
  21.     {   
  22.         global $db;   
  23.         $sqlStr = "SELECT count(*) FROM `{$dbTable}` {$sqlSuffix}";   
  24.         $this->rsCount    = $db->getResult($sqlStr);   
  25.         $this->pageCount  = ceil($this->rsCount / $eveNum);   
  26.         $this->pageBarNum = $pageBarNum;   
  27.         if ($curPage < 1) {   
  28.             $this->curPage = 1;   
  29.         } elseif ($curPage > $this->pageCount) {   
  30.             $this->curPage = $this->pageCount;   
  31.         } else {   
  32.             $this->curPage = $curPage;   
  33.         }   
  34.         $this->rsOffset = ($this->curPage - 1) * $eveNum;;   
  35.         $sqlStr = "SELECT *  
  36.             FROM `{$dbTable}`  
  37.             {$sqlSuffix}  
  38.             ORDER BY `id` DESC  
  39.             LIMIT {$this->rsOffset},{$eveNum}";   
  40.         $this->queryId   = $db->query($sqlStr);   
  41.         $this->getNum();   
  42.     }   
  43.   
  44.     // 分页条   
  45.     function getNum()   
  46.     {   
  47.         $chk1 = floor($this->pageBarNum / 2);   
  48.         $chk2 = ceil($this->pageBarNum / 2);   
  49.         if ($this->pageCount <= $this->pageBarNum) {   
  50.             $this->startNum = 1;   
  51.             $this->endNum   = $this->pageCount;   
  52.         } else {   
  53.             if ($this->curPage <= $chk1) {   
  54.                 $this->startNum = 1;   
  55.                 $this->endNum   = $this->pageBarNum;   
  56.             } elseif ($this->curPage + $chk1 > $this->pageCount) {   
  57.                 $this->startNum = $this->pageCount - $this->pageBarNum + 1;   
  58.                 $this->endNum   = $this->pageCount;   
  59.             } else {   
  60.                 $this->startNum = $this->curPage - $chk2 + 1;   
  61.                 $this->endNum   = $this->curPage + $chk1;   
  62.             }   
  63.         }   
  64.         if ($this->curPage == 1) {   
  65.             $this->prevPage = 1;   
  66.         } else {   
  67.             $this->prevPage = $this->curPage - 1;   
  68.         }   
  69.         if ($this->curPage == $this->pageCount) {   
  70.             $this->nextPage = $this->pageCount;   
  71.         } else {   
  72.             $this->nextPage = $this->curPage + 1;   
  73.         }/*  
  74.         $urlSuffix = explode('&', $_SERVER['QUERY_STRING']);  
  75.         foreach($urlSuffix as $k => $v) {  
  76.             $v = explode('=', $v);  
  77.             if ($v[0] == 'page') {  
  78.                 unset($urlSuffix[$k]);  
  79.             }  
  80.         }  
  81.         $urlSuffix = join('&', $urlSuffix);*/  
  82.         $urlSuffix = $_GET;   
  83.         if (array_key_exists('page'$urlSuffix)) {   
  84.             unset($urlSuffix['page']);   
  85.         }   
  86.         $urlSuffix = http_build_query($urlSuffix);   
  87.         $this->urlSuffix = !emptyempty($urlSuffix) ? $urlSuffix.'&' : '';   
  88.     }   
  89.   
  90.     function getBar()   
  91.     {   
  92.         $pageBar =  <<<EOT   
  93. <div id="pagelist">   
  94. <ul>   
  95.     <li>共{$this->rsCount}条 第{$this->curPage}/{$this->pageCount}页</li>   
  96.     <li><a href="?{$this->urlSuffix}page=1" title="第一页">|<</a></li>   
  97.     <li><a href="?{$this->urlSuffix}page={$this->prevPage}" title="上一页"><<</a></li>/n   
  98. EOT;   
  99.         for ($i = $this->startNum; $i <= $this->endNum; $i++) {   
  100.             if ($i != $this->curPage) {   
  101.                 $pageBar .= "    <li><a href=/"?{$this->urlSuffix}page={$i}/" title=/"第 {$i} 页/">" . $i . "</a></li>/n";   
  102.             } else {   
  103.                 $pageBar .= "    <li><a title=/"当前第 {$i} 页/"><b>" . $i ."</b></a></li>/n";   
  104.             }   
  105.         }   
  106.         $pageBar .= <<<EOT   
  107.     <li><a href="?{$this->urlSuffix}page={$this->nextPage}" title="下一页">>></a></li>   
  108.     <li><a href="?{$this->urlSuffix}page={$this->pageCount}" title="最后一页">>|</a></li>   
  109. </ul>   
  110. </div>   
  111. EOT;   
  112.         return $pageBar;   
  113.     }   
  114.   
  115.     // 数据集   
  116.     function getRS()   
  117.     {   
  118.         return $this->queryId;   
  119.     }   
  120.     // 数据总数   
  121.     function getRSC()   
  122.     {   
  123.         return $this->rsCount;   
  124.     }   
  125.     // 记录编号偏移量   
  126.     function getRSN()   
  127.     {   
  128.         return $this->rsCount - $this->rsOffset;   
  129.     }   
  130. }   
  131.   
  132. class newpage extends page   
  133. {   
  134.     function getBar()   
  135.     {   
  136.         $pageBar =  <<<EOT   
  137. <div id="pagelist">   
  138. <ul>   
  139.     <li>共{$this->rsCount}条 第{$this->curPage}/{$this->pageCount}页</li>   
  140.     <li><a href="?{$this->urlSuffix}page=1" title="第一页">首</a></li>   
  141.     <li><a href="?{$this->urlSuffix}page={$this->prevPage}" title="上一页">上</a></li>/n   
  142. EOT;   
  143.         $pageBar .= <<<EOT   
  144.     <li><a href="?{$this->urlSuffix}page={$this->nextPage}" title="下一页">下</a></li>   
  145.     <li><a href="?{$this->urlSuffix}page={$this->pageCount}" title="最后一页">末</a></li>   
  146. </ul>   
  147. </div>   
  148. EOT;   
  149.         return $pageBar;   
  150.     }   
  151. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值