PHP ページング コード、美しいスタイルの PHP ページング コード

WBOY
リリース: 2016-07-25 08:52:46
オリジナル
1109 人が閲覧しました
  1. include "pager.class.php";
  2. $CurrentPage=isset($_GET['ページ'])?$_GET['ページ']: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. echo $pageStr;
  10. ?>
复制代
  1. php分页演示-bbs.it-home.org
  2. <ボディ>
  3. include "pager.class.php";
  4. $CurrentPage=isset($_GET['ページ'])?$_GET['ページ']:1;
  5. //死($CurrentPage);
  6. $myPage=新しいページャー(1300,intval($CurrentPage));
  7. $pageStr= $myPage->GetPagerContent();
  8. //echo $pageStr;
  9. $myPage=新しいページャー(90,intval($CurrentPage));
  10. $pageStr= $myPage->GetPagerContent();
  11. echo $pageStr;
  12. ?>
复制代

2) pager.class.php:

  1. /*

  2. * PHP分页类
  3. * @package Page
  4. * @Created 2013-03-27
  5. * @Modify 2013-03-27
  6. * 例:
  7. $myPage=新しいページャー(1300,intval($CurrentPage));
  8. $pageStr= $myPage->GetPagerContent();
  9. echo $pageStr;
  10. */
  11. class Pager {
  12. private $pageSize = 10;
  13. プライベート $pageIndex;
  14. private $totalNum;

  15. private $totalPagesCount;

  16. private $pageUrl;

  17. プライベート static $_instance;

  18. パブリック関数 __construct($p_totalNum, $p_pageIndex, $p_pageSize = 10,$p_initNum=3,$p_initMaxNum=5) {

  19. if (! isset ( $p_totalNum ) || !isset($p_pageIndex)) {
  20. die ( "ページャー初期エラー" );
  21. }

  22. $this->totalNum = $p_totalNum;

  23. $this->pageIndex = $p_pageIndex;
  24. $this->pageSize = $p_pageSize;
  25. $this->initNum=$p_initNum;
  26. $this->initMaxNum=$p_initMaxNum;
  27. $this->totalPagesCount= ceil($p_totalNum / $p_pageSize);
  28. $this->pageUrl=$this->_getPageUrl();

  29. $this->_initPagerLegal();

  30. }

  31. /**
  32. * ページ部分を削除した現在の URL 文字列を取得します
  33. *
  34. * @return String URL 文字列
  35. */
  36. プライベート関数 _getPageUrl() {
  37. $CurrentUrl = $_SERVER["REQUEST_URI"];
  38. $arrUrl = parse_url($CurrentUrl);
  39. $urlQuery = $arrUrl["クエリ"];

  40. if($urlQuery){

  41. $urlQuery = ereg_replace("(^|&)page=" . $this->pageIndex 、「」、$urlQuery);
  42. $CurrentUrl = str_replace($arrUrl["query"], $urlQuery, $CurrentUrl);

  43. if($urlQuery){

  44. $CurrentUrl.="&page";
  45. }
  46. else $CurrentUrl.="?page";

  47. } else {

  48. $CurrentUrl.="?page";
  49. }

  50. return $CurrentUrl;

  51. }

  52. /*
  53. *设置页面パラメータ合法性
  54. *@return void
  55. */
  56. private function _initPagerLegal( )
  57. {
  58. if((!is_numeric($this->pageIndex)) || $this->pageIndex{
  59. $this->pageIndex=1;
  60. }elseif($this->pageIndex > $this->totalPagesCount)
  61. {
  62. $this->pageIndex=$this->totalPagesCount;
  63. }

  64. }

  65. //$this->pageUrl}={$i}
  66. //{$this->CurrentUrl}={$this->TotalPages}
  67. public function GetPagerContent () {
  68. $str = "
    ";
  69. //首页 上一页
  70. if($this->pageIndex==1)
  71. {
  72. $str .="首页 "."n";
  73. $str .="上一页 "."n"."n" ;
  74. }else
  75. {
  76. $str .="首页 "."n ";
  77. $str .="上一页 "."n"."n";
  78. }
  79. /*

  80. 除首末後页面分页逻辑

  81. */
  82. //10页(含)以下
  83. $currnt="";
  84. if($this->totalPagesCount<=10)
  85. {

  86. for($i=1;$i<=$this->totalPagesCount;$i++)

  87. {

  88. if($i==$this->pageIndex)
  89. { $currnt=" class='current'";}
  90. else
  91. { $currnt=""; }
  92. $str .="$i"."n" ;
  93. }
  94. }else //10页以上
  95. { if($this->pageIndex{
  96. for($i=1;$i<=3;$i++)
  97. {
  98. if($i==$this->pageIndex)
  99. { $currnt=" class='current'";}
  100. else
  101. { $currnt=""; }
  102. $str .="$i"."n" ;
  103. }

  104. $str.="……"."n";

  105. for($i=$this->totalPagesCount-3+1;$i<=$this->totalPagesCount;$i++ )//功能1

  106. {
  107. $str .="$i"."n" ;
  108. }

  109. }elseif($this->pageIndex<=5) // 5 >=現在前页 >= 3
  110. {
  111. for($i=1;$i<=($ this->pageIndex+1);$i++)
  112. {
  113. if($i==$this->pageIndex)
  114. { $currnt=" class='current'";}
  115. else
  116. { $currnt=" "; }
  117. $str .="$i"."n" ;
  118. }

  119. $str.="……"."n";

  120. for($ i=$this->totalPagesCount-3+1;$i<=$this->totalPagesCount;$i++)// 功能1

  121. {
  122. $str .="$i"."n" ;
  123. }

  124. }elseif(5<$this->pageIndex && $this- >pageIndex<=$this->totalPagesCount-5 ) //現在の页数は 5 より大きく、同時に总页数-5 よりも小さい

  125. {

  126. for( $i=1;$i<=3;$i++)

  127. {
  128. $str .="$i "."n" ;
  129. }
  130. $str.="……";
  131. for($i=$this->pageIndex-1 ;$i<=$this->pageIndex+1 && $i<=$this->totalPagesCount-5+1;$i++)
  132. {
  133. if ($i==$this->pageIndex)
  134. { $currnt=" class='current'";}
  135. else
  136. { $currnt=""; }
  137. $str .="$i"."n" ;
  138. }
  139. $str.="……";

  140. for($i=$this->totalPagesCount-3 +1;$i<=$this->totalPagesCount;$i++)

  141. {
  142. $str .="$i< /a>"."n" ;

  143. }

  144. }else
  145. {

  146. for($i=1;$i<=3;$i++ )

  147. {
  148. $str .="$i"."n" ;
  149. }
  150. $str.="……"."n";

  151. for($i=$this->) ;totalPagesCount-5;$i<=$this->totalPagesCount;$i++)//功能1

  152. {
  153. if($i==$this->pageIndex)
  154. { $currnt=" class='current' ";}
  155. else
  156. { $currnt=""; }
  157. $str .="$i"."n" ;

  158. }

  159. }
  160. }

  161. /*

  162. 除首末後页面分页逻辑结束
  163. */
  164. //下一页末页
  165. if($this->pageIndex ==$this->totalPagesCount)
  166. {
  167. $str .="n"."下一页"."n" ;
  168. $str .="末页"."n";

  169. }else
  170. {
  171. $str .="n"."下一页 "."n";
  172. $str .="末页 "."n" ;
  173. }

  174. $str .= "

";
  • $str; を返します。
  • }

  • /**

  • * インスタンスを取得
  • * @return
  • */
  • // static public function getInstance() {
  • // if (is_null ( self::$_instance )) {
  • // self: :$_instance = 新しいページャー ();
  • // }
  • // return self::$_instance;
  • // }

  • }
  • ?>

  • 复制代

    3),php分页样式文件 pager.css:

    1. body,html{padding:0px;マージン:0px;色:#333333; font-family:"宋体"、Arial、Lucida、Verdana、Helvetica、サンセリフ;フォントサイズ:12px;行の高さ:150%;}

    2. h1,h2,h3,h4,h5,h6,ul,li,dl,dt,dd,form,img,p,label{margin:0;パディング:0;境界線:なし; list-style-type:none;}

    3. /**フロントページのページネーションのスタイル**/

    4. .Pagination {margin:10px 0 0;padding:5px 0;text-align:rightright;高さ:20ピクセル;行の高さ:20px; font-family:Arial, Helvetica, sans-serif,"宋体";}
    5. .Pagination a {margin-left:2px;padding:2px 7px 2px;}
    6. .Pagination .dot{ border:medium none; padding:4px 8px}
    7. .Pagination a:link, .Pagination a:visited {border:1px Solid #dedede;color:#696969;text-decoration:none;}
    8. .Pagination a:hover, .Pagination a:active, .Pagination a.current:link、.Pagination a.current:visited {border:1px Solid #dedede;color:#fff;背景色:#ff6600;背景画像:なし; border:#ff6600 ソリッド 1px;}
    9. .Pagination .selectBar{ border:#dedede ソリッド 1px;フォントサイズ:12px;幅:95ピクセル;高さ:21ピクセル;行の高さ:21px;マージン左:10px; display:inline}
    10. .Pagination a.tips{_padding:4px 7px 1px;}

    复制代码


    ソース:php.cn
    このウェブサイトの声明
    この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
    最新の問題
    人気のチュートリアル
    詳細>
    最新のダウンロード
    詳細>
    ウェブエフェクト
    公式サイト
    サイト素材
    フロントエンドテンプレート
    私たちについて 免責事項 Sitemap
    PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!