VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > PHP >
  • php通用翻页类,支持上一页和下一页

  1. function fPageCount($TotalResult,$numPerPage,$Page){ 
  2.     $NaviLength='10' ; //显示数量 
  3.     $showMorePageGo_Type_=0; //跳转样式 
  4.     $int_showNumberLink_='十'
  5.     $nonLinkColor_="#999999";  
  6.     $toF_="<font face=webdings title='首页'>9</font>" ; 
  7.     $toP10_=" <font face=webdings title='上十页'>7</font>"
  8.     $toP1_=" <font face=webdings title='上一页'>3</font>"
  9.     $toN1_=" <font face=webdings title='下一页'>4</font>"
  10.     $toN10_=" <font face=webdings title='下十页'>8</font>";  
  11.     $toL_="<font face=webdings title='最后一页'>:</font>";  
  12.     $page_index = ""
  13.  
  14.     $tpagecount = ceil($TotalResult/$numPerPage); 
  15. $nowCoolPage=ceil($Page/$NaviLength); 
  16.     $toPage_ = $_SERVER['QUERY_STRING']; 
  17.     if ( $toPage_ == '' ) { 
  18.        $toPage_ = "?page=";  
  19.     }else { 
  20.        $toPage_ = preg_replace("/&?page=d+/"'', $toPage_); 
  21.        $toPage_ = "?".$toPage_."&page="
  22.     } 
  23.       
  24. if($nowCoolPage == 1){ 
  25.         $page_index.="<font color=".$nonLinkColor_." title='首页'>".$toF_."</font> "
  26.         $page_index.="<font color=".$nonLinkColor_." title='上".$int_showNumberLink_."页'>".$toP10_."</font> "
  27.     }else
  28.         $preRow =  $Page-$NaviLength; 
  29.   $page_index.="<a href=".$toPage_."1 title='首页'>".$toF_."</a> "
  30.   $page_index.="<a href=".$toPage_.$preRow." title='上".$int_showNumberLink_."页'>".$toP10_."</a> "
  31.     }  
  32.     $upRow   = $Page-1; 
  33.     $downRow = $Page+1; 
  34.     if ($upRow>0){ 
  35.        $page_index.="<a href=".$toPage_.$upRow." title='上一页'>".$toP1_."</a> "
  36.     }else
  37.        $page_index.="<font color=".$nonLinkColor_." title='上一页'>".$toP1_."</font> "
  38.     }  
  39.       
  40. for($i=1;$i<=$NaviLength;$i++){ 
  41.          $nowPage=($nowCoolPage-1)*$NaviLength+$i; 
  42.          if($nowPage!=$Page){ 
  43.              if($nowPage<=$tpagecount){ 
  44.                  $page_index.="  <a href=".$toPage_.$nowPage.">" .$nowPage. "</a> "
  45.              }else
  46.                  break
  47.              } 
  48.          }else
  49.              if($tpagecount != 1){ 
  50.                 $page_index.="<b>".$nowPage."</b>"
  51.              } 
  52.          } 
  53.       } 
  54.      if ($downRow <= $tpagecount){ 
  55.          $page_index.="<a href=".$toPage_.$downRow." title='下一页'>".$toN1_."</a> "
  56.      }else
  57.          $page_index.="<font color=".$nonLinkColor_." title='下一页'>".$toN1_."</font> "
  58.      } 
  59.      if($nowCoolPage == $tpagecount){ 
  60.          $page_index.=" <font color=".$nonLinkColor_." title='下".$int_showNumberLink_."页'>".$toN10_."</font> "
  61.          $page_index.="<font color=".$nonLinkColor_." title='尾页'>".$toL_."</font>"
  62.      }else
  63.          $nextRow = $Page+$NaviLength; 
  64.          $theEndRow = $tpagecount; 
  65.          $page_index.=" <a href=".$toPage_.$nextRow." title='下".$int_showNumberLink_."页'>".$toN10_."</a> "
  66.          $page_index.="<a href=".$toPage_.$theEndRow." title='尾页'>".$toL_."</a>"
  67.      } 
  68.     if ($showMorePageGo_Type_ ==1){ 
  69.       $Show_Page_i = $Page + 1 ; 
  70.     if ($Show_Page_i>$tpagecount) $Show_Page_i = 1;  
  71.     $page_index.="  跳转<input type='text' id='skip' value='' onkeyup='this.value=this.value.replace(/[^d]+/,'')' style='width:40px'/>  <input type='button' value='确定' class='btn' onclick='location.href='?page='+$('skip').value+'".$toPage_."';'/>n"
  72.        }else
  73.        $page_index.=" 跳转:<select name='select' size='1' style='font-size: 12px' onchange='javascript:window.location.href=this.options[this.selectedIndex].value'>";  
  74.      for($i=1;$i<=$tpagecount;$i++){ 
  75.      if($Page==$i){ 
  76.         $selected=" selected"
  77.      }else
  78.         $selected=""
  79.         } 
  80.         $page_index.=" <option value=".$toPage_.$i;  
  81.         $page_index.=$selected." style='color:#FF0000'";  
  82.         $page_index.=">第".$i."页</option>"
  83.      }//开源代码phpfensi.com 
  84.         $page_index.="</select>"
  85.    } 
  86.         $page_index.=$p_.$sp2_."  每页<b>".$numPerPage."</b>个记录,现在是:<b><span class='tx'>".$sp2_.$Page."</span>/".$tpagecount."</b>页,共<b><span id='recordcount'>".$sp2_.$TotalResult."</span></b>个记录。";  
  87.     return $page_index;  

 

例子:<?php echo fPageCount($TotalResult,$numPerPage,$page)?> $TotalResult 代表总数 $numPerPage 每页显示数量 $page 页码.

 



出处:http://www.phpfensi.com/php/20140909/5165.html


相关教程