搜尋
首頁後端開發php教程php分頁類別程式碼,帶有漂亮樣式的php分頁程式碼

  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
    PHP依賴注入容器:快速啟動PHP依賴注入容器:快速啟動May 13, 2025 am 12:11 AM

    aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增強codemodocultion,可驗證性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

    PHP中的依賴注入與服務定位器PHP中的依賴注入與服務定位器May 13, 2025 am 12:10 AM

    選擇DependencyInjection(DI)用於大型應用,ServiceLocator適合小型項目或原型。 1)DI通過構造函數注入依賴,提高代碼的測試性和模塊化。 2)ServiceLocator通過中心註冊獲取服務,方便但可能導致代碼耦合度增加。

    PHP性能優化策略。PHP性能優化策略。May 13, 2025 am 12:06 AM

    phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)啟用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替換loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

    PHP電子郵件驗證:確保正確發送電子郵件PHP電子郵件驗證:確保正確發送電子郵件May 13, 2025 am 12:06 AM

    phpemailvalidation invoLvesthreesteps:1)格式化進行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)

    如何使PHP應用程序更快如何使PHP應用程序更快May 12, 2025 am 12:12 AM

    tomakephpapplicationsfaster,關注台詞:1)useopcodeCachingLikeLikeLikeLikeLikePachetoStorePreciledScompiledScriptbyTecode.2)MinimimiedAtabaseSqueriSegrieSqueriSegeriSybysequeryCachingandeffeftExting.3)Leveragephp7 leveragephp7 leveragephp7 leveragephpphp7功能forbettercodeefficy.4)

    PHP性能優化清單:立即提高速度PHP性能優化清單:立即提高速度May 12, 2025 am 12:07 AM

    到ImprovephPapplicationspeed,關注台詞:1)啟用opcodeCachingwithapCutoredUcescriptexecutiontime.2)實現databasequerycachingingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandreduceconnection.4 limitesclection.4.4

    PHP依賴注入:提高代碼可檢驗性PHP依賴注入:提高代碼可檢驗性May 12, 2025 am 12:03 AM

    依赖注入(DI)通过显式传递依赖关系,显著提升了PHP代码的可测试性。1)DI解耦类与具体实现,使测试和维护更灵活。2)三种类型中,构造函数注入明确表达依赖,保持状态一致。3)使用DI容器管理复杂依赖,提升代码质量和开发效率。

    PHP性能優化:數據庫查詢優化PHP性能優化:數據庫查詢優化May 12, 2025 am 12:02 AM

    DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

    See all articles

    熱AI工具

    Undresser.AI Undress

    Undresser.AI Undress

    人工智慧驅動的應用程序,用於創建逼真的裸體照片

    AI Clothes Remover

    AI Clothes Remover

    用於從照片中去除衣服的線上人工智慧工具。

    Undress AI Tool

    Undress AI Tool

    免費脫衣圖片

    Clothoff.io

    Clothoff.io

    AI脫衣器

    Video Face Swap

    Video Face Swap

    使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

    熱門文章

    熱工具

    SecLists

    SecLists

    SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

    SublimeText3 英文版

    SublimeText3 英文版

    推薦:為Win版本,支援程式碼提示!

    Safe Exam Browser

    Safe Exam Browser

    Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

    Dreamweaver CS6

    Dreamweaver CS6

    視覺化網頁開發工具

    Atom編輯器mac版下載

    Atom編輯器mac版下載

    最受歡迎的的開源編輯器