国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php 遠程分頁類

2024-05-04 23:06:53
字體:
來源:轉載
供稿:網友

page_total_rows - 每頁展示數量 默認值20

$total_rows - 總計數據條目數

$totpages - 總頁數計算

$pages_current - 當前頁面

利用url參數傳遞 當前頁碼 url參數名稱 pages

$style - 頁碼展示樣式可以通過外部訪問樣式屬性進行修改

***********************使用方法**********************

調用該類:$pages = new pages;

調用該類后請修改數據集總條數

$pages->total_rows = $totrows;

$pages->main();方法將返回limit需要的2個參數 關聯數組的a,b2個元素

$limit = $pages->main();

通過訪問不同方法即可展示不同的功能!

PHP遠程分頁類實例代碼如下:
  1. <?php 
  2. class pages{ 
  3. public $page_total_rows = 20;//每頁展示數量 
  4. public $total_rows;//總計數據條目數 
  5. public $totpages;//總頁數 
  6. public $current_url;//當前頁面名稱 
  7. private $ask//是否出現問號 
  8. public $style ='<style type="text/css教程"
  9. .pages_norename{width:50px; height:20px; float:left; background-color:#e3eff3; margin-right:5px; text-align:center; line-height:20px; border:1px solid #333333;} 
  10. .pages_norename a{display:block; width:50px; height:20px; color:#333333; text-decoration:none;} 
  11. .pages_norename a:hover{background-color:#ff9900; color:#ffffff;} 
  12. .pages_nore_more{width:auto; height:20px; float:left; margin-right:5px; line-height:20px; background-color:#e3eff3; border:1px solid #333333;} 
  13. .pages_nore_more a{display:block; width:20px; height:20px; color:#333333; text-decoration:none; text-align:center;} 
  14. .pages_nore_more a:hover{background-color:#ff9900; color:#ffffff;} 
  15. .pages_se{width:auto; height:20px; float:left;} 
  16. .pages_se select{margin:0px; padding:0px; font-family:arial, helvetica, sans-serif; font-size:12px;} 
  17. </style> 
  18. '; 
  19. //核心計算 并以數組的形式返回查詢sql 語句的必須值 limit a,b; 
  20. function main(){ 
  21.   $this->totpages = ceil($this->total_rows/$this->page_total_rows);//總頁數計算 
  22.   //獲得當前頁碼------------------- 
  23.   if(!isset($_get['pages'])) 
  24.   { 
  25.   $this->pages_current = 1; 
  26.   }else 
  27.   { 
  28.    $this->pages_current = intval($_get['pages']); 
  29.    //判斷頁面不為0 
  30.    if($this->pages_current < 1){ 
  31.    $this->pages_current = 1; 
  32.    }//開源代碼Vevb.com 
  33.    //判斷頁面不能大于最大頁碼數量 
  34.    if($this->pages_current > $this->totpages){ 
  35.    $this->pages_current = $this->totpages; 
  36.    } 
  37.    //注銷url 參數 pages 和 total_rows 為了更好的傳遞其他url參數 
  38.    if(isset($_get['pages'])){unset($_get['pages']);} 
  39.    if(isset($_get['total_rows'])){unset($_get['total_rows']);} 
  40.     
  41.   } 
  42.   //獲得當前頁碼-------------------- 
  43.   $limit['a'] = $start = ($this->pages_current - 1)*$this->page_total_rows; 
  44.   $limit['b'] = $this->page_total_rows; 
  45.   //獲得當前頁面名稱 
  46.   $urlin = explode('/',$_server['php教程_self']); 
  47.    
  48.   $tot_url = sizeof($urlin); 
  49.   $this->current_url =$urlin[$tot_url-1]; 
  50.   //獲得當前頁面傳遞的url 
  51.   if(sizeof($_get) > 0){ 
  52.    foreach($_get as $key=>$values){ 
  53.     $urlsget .= $key.'='.$values.'&'
  54.    } 
  55.    $this->current_url .= '?'.$urlsget
  56.    $this->ask = ''
  57.   }else{$this->ask = '?';} 
  58.   //輸出樣式 
  59.   echo $this->style; 
  60.   return $limit
  61. //展示分頁 
  62. //1 第一頁 
  63. function firstpage(){ 
  64.   echo '<div class="pages_norename"><a href="'.$this->current_url.'">首頁</a></div>'
  65. //2 上一頁 
  66. function prepage(){ 
  67.   echo '<div class="pages_norename"><a href="'.$this->current_url.$this->ask.'pages='.($this->pages_current-1).'">上一頁</a></div>'
  68. //3 下一頁 
  69. function nextpage(){ 
  70.   echo '<div class="pages_norename"><a href="'.$this->current_url.$this->ask.'pages='.($this->pages_current+1).'">下一頁</a></div>'
  71. //4 最后一頁 
  72. function  lastpage(){ 
  73.   echo '<div class="pages_norename"><a href="'.$this->current_url.$this->ask.'pages='.($this->totpages).'">尾頁</a></div>'
  74. //中間過渡頁 
  75. function morepage(){ 
  76.   if($this->pages_current == 1){$newtj = $this->pages_current+9;} 
  77.   elseif($this->pages_current  == 2){$newtj = $this->pages_current+8;} 
  78.   elseif($this->pages_current == 3){$newtj = $this->pages_current+7;} 
  79.   else{$newtj = $this->pages_current+6;} 
  80.    for($i=$this->pages_current-3;$i<=$newtj;$i++){ 
  81.     if($i==$this->pages_current){$strong ='<strong>'$strong2 ='</strong>';}else{$strong='';$strong2='';} 
  82.     if($i >=1){echo '<div class="pages_nore_more"><a href="'.$this->current_url.$this->ask.'pages='.$i.'">'.$strong.$i.$strong2.'</a></div>';} 
  83.     if($i >= $this->totpages){ 
  84.     break
  85.     } 
  86.    } 
  87. //跳轉頁面 
  88. function changepage(){ 
  89.   echo '<div class="pages_se"><select name="dd">'
  90.   for($i=1;$i<=$this->totpages;$i++){ 
  91.   if($this->pages_current == $i){$selected = ' selected="selected"';}else{$selected = '';} 
  92.   echo '<option value="'.$i.'"'.$selected.'>第'.$i.'頁</option>'
  93.   } 
  94.   echo '</select></div>'
  95. ?> 

該類可以自動識別 url 參數,避免了一般分頁類丟失url參數問題,樣式可以通過style屬性進行修改,提供 首頁 上一頁 下一頁 尾頁 中間 過渡頁 跳轉菜單功能.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 恩施市| 华安县| 观塘区| 宜兰市| 孝昌县| 曲靖市| 乾安县| 沂水县| 五华县| 荥经县| 大悟县| 嵊泗县| 鄂伦春自治旗| 安新县| 内乡县| 社旗县| 乌拉特后旗| 阳信县| 寻甸| 乐业县| 名山县| 房产| 萝北县| 江北区| 枣庄市| 石棉县| 茶陵县| 台前县| 资兴市| 会昌县| 舒城县| 芜湖市| 昭苏县| 晴隆县| 瑞金市| 辽阳市| 扬中市| 内黄县| 乐昌市| 罗源县| 安庆市|