首頁  >  文章  >  後端開發  >  php分頁類別程式碼,帶有漂亮樣式的php分頁程式碼

php分頁類別程式碼,帶有漂亮樣式的php分頁程式碼

WBOY
WBOY原創
2016-07-25 08:52:461160瀏覽
  1. include "pager.class.php";
  2. $CurrentPage=isset($_GET['page'])?$_GET[ 'page']:1;
  3. //死亡($CurrentPage);
  4. $myPage=新尋呼機(1300,intval($CurrentPage));
  5. $pageStr= $myPage->GetPagerContent();
  6. //echo $pageStr;
  7. $myPage=新尋呼機(90,intval($CurrentPage));
  8. $pageStr= $myPage->GetPagerContent();
  9. 回顯$pageStr;
  10. ?>
複製程式碼
  1. >
  2. php分頁示範-bbs.it-home.org
  3. >
  4. 頭>
  5. include "pager.class.php";
  6. $CurrentPage=isset($_GET['page'])?$_GET['page']:1;
  7. //死亡($CurrentPage);
  8. $myPage=新尋呼機(1300,intval($ CurrentPage));
$pageStr= $myPage->GetPagerContent();
//echo $pageStr; $myPage=新尋呼機(90,intval($CurrentPage)); $pageStr = $myPage->GetPagerContent();
回顯$pageStr; ? > 身體> 複製程式碼

2) pager.class.php:

  1. 建立於2013-03-27 * @Modify 2013-03-27

  2. * 範例:
  3. $myPage =新尋呼機(1300,intval($CurrentPage));
  4. $pageStr= $myPage->GetPagerContent();
  5. 回顯$pageStr;
  6. */
  7. class Pager {
  8. private pageSize = 10;
  9. 私有$pageIndex;
  10. 私人$totalNum;
  11. 私人$totalPagesCount;

  12. 私人$pageUrl;

  13. private static $_instance;
  14. public function __construct($p_totalNum, $p_pageIndex, $p_pageSize = 10, $p_initNum=3, $p_initMaxNum=5) {

  15. if (! ) || !isset($p_pageIndex)) {
  16. die("頁面初始化錯誤");
  17. }
  18. $this->totalNum = $p_totalNum;

  19. $ this->pageIndex = $p_pageIndex;
  20. $this->pageSize = $p_pageSize;
  21. $this->initNum=$p_initNum;
  22. $this->initMaxNum=$p_inMaxNum; >totalPagesCount= ceil($p_totalNum / $p_pageSize);
  23. $this->pageUrl=$this->_getPageUrl();
  24. $this->_initPagerLegal();

  25. }
  26. /**
  27. * 取得移除page部分的目前網址
  28. *
  29. * @return String URL字串
  30. */
  31. 私有函數_getPageUrl() {
  32. $CurrentUrl = $_SERVER["REQUEST_URI"];
  33. $ arrUrl = parse_url($CurrentUrl);
  34. $urlQuery = $arrUrl["query"]
  35. $urlQuery = ereg_replace("(^|&)page=" $this🎜>$urlQuery = ereg_replace("(^|&)page=" $this🎜>$urlQuery = ereg_replace("(^|&)page=" $this🎜>$urlQuery = ereg_replace("(^|&)page=" $this🎜>$urlQuery = ereg_replace("(^|&)page=" $this - > pageIndex, "", $urlQuery);
  36. $CurrentUrl = str_replace($arrUrl["query"], $urlQuery, $CurrentUrl)";
  37. }
  38. else $CurrentUrl.="page" ;
  39. } else {

  40. $CurrentUrl.="?page";
  41. }
  42. return $CurrentUrl;

  43. } *@return void

  44. */
  45. 私人函數_initPagerLegal()
  46. {
  47. if((!is_numeric($this->pageIndex)) || $this->pageIndex {
  48. $this->pageIndex=1;
  49. }elseif($this->pageIndex > $this->totalPagesCount)
  50. {
  51. $this->pageIndex=$ this->totalPagesCount;
  52. }
  53. }

  54. //$this->pageUrl}={$i}
  55. / /{$this->CurrentUrl}={$this->pageUrl} TotalPages}
  56. public function GetPagerContent() {
  57. $str = "
  58. //可選鍵
  59. if($this->pageIndex==1)
  60. {
  61. $str .="tips;
  62. $str .="something "."n" n" ;
  63. }else
  64. {
  65. $str .=" tips a> ; “ n”;
  66. $str .="only a>
  67. }
  68. /*
  69. 甜美的雪花雪花

  70. */
  71. //10 片雪
  72. $currnt=" ";
  73. if($this->totalPagesCount{
  74. for($i=1;$itotalPagesCount;$ i )

  75. {

  76. if($i==$this-&pageIndex)
  77. { $currnt=" class='current'";}
  78. else
  79. { $currnt=""; }
  80. $str .="$i"."n" ;
  81. }
  82. }else //擷取10個鍵
  83. { if($this->pageIndex{
  84. for($i=1;$ i{
  85. if($i==$this->pageIndex)
  86. { $currnt=" class='current'";}
  87. else
  88. { $currnt="" ; }
  89. $str .="$i"."n" ;
  90. } p>
  91. $str.="span class="dot">。"."n";

  92. for($i=$this->totalPagesCount-3 1;$itotalPagesCount;$ i )//功能1

  93. {
  94. $str .="$i"."n " ;
  95. }

  96. }elseif($this->pageIndex= 目前頁>= 3
  97. {
  98. for($i=1;$ipageIndex 1);$i )
  99. {
  100. if($i==$this->pageIndex)
  101. { $currnt =" class='current'";}
  102. else
  103. { $currnt="" }
  104. $str .="$i"."n " ;
  105. }

  106. $str.="……"."n";
  107. for($i=$this->totalPagesCount-3 1;$i ;totalPagesCount;$i )//功能1

  108. {
  109. $str .="$i "."n" ;
  110. }
  111. }elseif(5pageIndex && $this->pageIndextotalPagesCount-5 ) //當頁大於5,同時小於總頁數-5

  112. {

  113. for($i=1;$i{

  114. $str .="$i "."n" ;
  115. }
  116. $str.="……";
  117. for($i=$this-> pageIndex-1 ;$ipageIndex 1 && $itotalPagesCount-5 1;$i )
  118. {
  119. if($i==$this->pageIndex)
  120. { $currnt=" class='current'";}
  121. else
  122. { $currnt=""; }
  123. $str .="$i"."n" ;
  124. }
  125. $str.="……";
  126. for($i=$this ->totalPagesCount-3 1;$itotalPagesCount;$i )

  127. {
  128. $str .="$i a>"."n" ;
  129. }

  130. } 否則
  131. {
  132. for($i=1;$i{
  133. $str .="$i"."n" ;
  134. }
  135. $str.="……"."n";
  136. for($ i=$this- >totalPagesCount-5;$itotalPagesCount;$i )//功能1

  137. {
  138. if($i==$this->pageIndex)
  139. { $currnt=" class ='當前'";}
  140. 其他
  141. { $currnt=""; }
  142. $str .="$i"."n" ; p>
  143. }

  144. }
  145. }
  146. /*

  147. 除首末頁分頁邏輯結束
  148. */
  149. //下一頁末頁
  150. if($this->pageIndex==$this->totalPagesCount)
  151. {
  152. $str .="n"."下一頁"."n" ;
  153. $str .="末頁"."n"; p>
  154. }else
  155. {
  156. $str .="n"."下一頁 "."n";
  157. $str .="末頁一個>“。 n”;
  158. }
  159. $str .= "

";
  • 回傳$str
  • }
  • / * *

  • * 取得實例
  • * @return
  • */
  • // static public function getInstance() {
  • // if (is_null ( self::$_instance )) {
  • // self::$_instance = new pager ( ) ;
  • // }
  • // 回傳self::$_instance;
  • // }
  • }
  • ?>
  • 複製程式碼

    3),php分頁樣式檔pager.css:

    1. body,html{ padding:0px;邊距:0px;顏色:#333333;font-family:"宋體", Arial,Lucida,Verdana,Helvetica,sans-serif;字體大小:12px;行高:150%;}

    2. h1,h2,h3,h4,h5,h6,ul,li,dl,dt,dd,form ,img,p,label{邊距:0;填滿:0;邊框:無;list-style-type:none;}
    3. /**前台分頁樣式**/

    4. .分頁{margin:10px 0 0;padding:5px 0;text-align:對對對;高度:20px;行高:20px;font-family:Arial, Helvetica, sans-serif,"宋體";}
    5. .分頁a {margin-left:2px;padding:2px 7px 2px;}
    6. .分頁.dot{ border:medium none; padding:4px 8px}
    7. .Pagination a:link, .Pagination a:visited {border:1pxsolid #dedede;color:#696969;text-decoration:none;}
    8. .Pagination a:hover, .Pagination a:active, .Pagination a.current:link, .Pagination a.current:visited { border:1pxsolid #dedede;color:#fff;背景顏色:#ff6600;背景圖像:無;邊框:#ff6600 實心1px;}
    9. .Pagination .selectBar{ 邊框:#dededede 實心1px;字體大小:12px;寬度:95px;高度:21px;行高:21px;左邊距:10px; display:inline}
    10. .Pagination a.tips{_padding:4px 7px 1px;}
    複製程式碼


    陳述:
    本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn