php通用翻页类,支持上一页和下一页

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

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