Php paging code, php paging code with beautiful styles

Source: Internet
Author: User
Php paging code, php paging code with beautiful styles

  1. Include "pager. class. php ";
  2. $ CurrentPage = isset ($ _ GET ['Page'])? $ _ GET ['Page']: 1;
  3. // Die ($ CurrentPage );
  4. $ MyPage = new pager (1300, intval ($ CurrentPage ));
  5. $ PageStr = $ myPage-> GetPagerContent ();
  6. // Echo $ pageStr;
  7. $ MyPage = new pager (90, intval ($ CurrentPage ));
  8. $ PageStr = $ myPage-> GetPagerContent ();
  9. Echo $ pageStr;
  10. ?>

  1. Php paging demonstration -bbs.it-home.org
  2. Include "pager. class. php ";
  3. $ CurrentPage = isset ($ _ GET ['Page'])? $ _ GET ['Page']: 1;
  4. // Die ($ CurrentPage );
  5. $ MyPage = new pager (1300, intval ($ CurrentPage ));
  6. $ PageStr = $ myPage-> GetPagerContent ();
  7. // Echo $ pageStr;
  8. $ MyPage = new pager (90, intval ($ CurrentPage ));
  9. $ PageStr = $ myPage-> GetPagerContent ();
  10. Echo $ pageStr;
  11. ?>

2) pager. class. php:

  1. /*

  2. * PHP paging class
  3. * @ Package Page
  4. * @ Created 2013-03-27
  5. * @ Modify 2013-03-27
  6. * Example:
  7. $ MyPage = new Pager (1300, intval ($ CurrentPage ));
  8. $ PageStr = $ myPage-> GetPagerContent ();
  9. Echo $ pageStr;
  10. */
  11. Class Pager {
  12. Private $ pageSize = 10;
  13. Private $ pageIndex;
  14. Private $ totalNum;

  15. Private $ totalPagesCount;

  16. Private $ pageUrl;

  17. Private static $ _ instance;

  18. Public function _ construct ($ p_totalNum, $ p_pageIndex, $ p_pageSize = 10, $ p_initNum = 3, $ p_initMaxNum = 5 ){

  19. If (! Isset ($ p_totalNum) |! Isset ($ p_pageIndex )){
  20. Die ("pager initial error ");
  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. * Obtain the current URL string for page removal.
  33. *
  34. * @ Return String URL String
  35. */
  36. Private function _ getPageUrl (){
  37. $ CurrentUrl = $ _ SERVER ["REQUEST_URI"];
  38. $ ArrUrl = parse_url ($ CurrentUrl );
  39. $ UrlQuery = $ arrUrl ["query"];

  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. * Set the validity of page parameters
  54. * @ Return void
  55. */
  56. Private function _ initPagerLegal ()
  57. {
  58. If ((! Is_numeric ($ this-> pageIndex) | $ this-> pageIndex <1)
  59. {
  60. $ This-> pageIndex = 1;
  61. } Elseif ($ this-> pageIndex> $ this-> totalPagesCount)
  62. {
  63. $ This-> pageIndex = $ this-> totalPagesCount;
  64. }

  65. }

  66. // $ This-> pageUrl }={$ I}
  67. // {$ This-> CurrentUrl }={$ this-> TotalPages}
  68. Public function GetPagerContent (){
  69. $ Str ="

    ";

  70. // Homepage previous page
  71. If ($ this-> pageIndex = 1)
  72. {
  73. $ Str. = "homepage". "n ";
  74. $ Str. = "previous page". "n". "n ";
  75. } Else
  76. {
  77. $ Str. = "pageUrl} = 1 'class = 'tids' title = 'homepage'> homepage". "n ";
  78. $ Str. = "pageUrl} = ". ($ this-> pageIndex-1 ). "'class = 'tids' title = 'preput'> Previous Page ". "n ". "n ";
  79. }
  80. /*

  81. Page paging logic after the beginning and end

  82. */
  83. // Below 10 pages (inclusive)
  84. $ Currnt = "";
  85. If ($ this-> totalPagesCount <= 10)
  86. {

  87. For ($ I = 1; $ I <= $ this-> totalPagesCount; $ I ++)

  88. {

  89. If ($ I ==$ this-> pageIndex)
  90. {$ Currnt = "class = 'current '";}
  91. Else
  92. {$ Currnt = "";}
  93. $ Str. = "pageUrl }={$ I} '{$ currnt}> $ I". "n ";
  94. }
  95. } Else // more than 10 pages
  96. {If ($ this-> pageIndex <3) // The current page is smaller than 3
  97. {
  98. For ($ I = 1; $ I <= 3; $ I ++)
  99. {
  100. If ($ I ==$ this-> pageIndex)
  101. {$ Currnt = "class = 'current '";}
  102. Else
  103. {$ Currnt = "";}
  104. $ Str. = "pageUrl }={$ I} '{$ currnt}> $ I". "n ";
  105. }

  106. $ Str. = "...... "." N ";

  107. For ($ I = $ this-> totalPagesCount-3 + 1; $ I <= $ this-> totalPagesCount; $ I ++) // Function 1

  108. {
  109. $ Str. = "pageUrl }={$ I} '> $ I". "n ";

  110. }

  111. } Elseif ($ this-> pageIndex <= 5) // 5> = current page> = 3
  112. {
  113. For ($ I = 1; $ I <= ($ this-> pageIndex + 1); $ I ++)
  114. {
  115. If ($ I ==$ this-> pageIndex)
  116. {$ Currnt = "class = 'current '";}
  117. Else
  118. {$ Currnt = "";}
  119. $ Str. = "pageUrl }={$ I} '{$ currnt}> $ I". "n ";

  120. }

  121. $ Str. = "...... "." N ";

  122. For ($ I = $ this-> totalPagesCount-3 + 1; $ I <= $ this-> totalPagesCount; $ I ++) // Function 1

  123. {
  124. $ Str. = "pageUrl }={$ I} '> $ I". "n ";
  125. }

  126. } Elseif (5 <$ this-> pageIndex & $ this-> pageIndex <= $ this-> totalPagesCount-5) // The current page is larger than 5 and smaller than the total page number-5

  127. {

  128. For ($ I = 1; $ I <= 3; $ I ++)

  129. {
  130. $ Str. = "pageUrl }={$ I} '> $ I". "n ";
  131. }
  132. $ Str. = "...... ";
  133. For ($ I = $ this-> pageIndex-1; $ I <= $ this-> pageIndex + 1 & $ I <= $ this-> totalPagesCount-5 + 1; $ I ++)
  134. {
  135. If ($ I ==$ this-> pageIndex)
  136. {$ Currnt = "class = 'current '";}
  137. Else
  138. {$ Currnt = "";}
  139. $ Str. = "pageUrl }={$ I} '{$ currnt}> $ I". "n ";
  140. }
  141. $ Str. = "...... ";

  142. For ($ I = $ this-> totalPagesCount-3 + 1; $ I <= $ this-> totalPagesCount; $ I ++)

  143. {
  144. $ Str. = "pageUrl }={$ I} '> $ I". "n ";

  145. }

  146. } Else
  147. {

  148. For ($ I = 1; $ I <= 3; $ I ++)

  149. {
  150. $ Str. = "pageUrl }={$ I} '> $ I". "n ";
  151. }
  152. $ Str. = "...... "." N ";

  153. For ($ I = $ this-> totalPagesCount-5; $ I <= $ this-> totalPagesCount; $ I ++) // Function 1

  154. {
  155. If ($ I ==$ this-> pageIndex)
  156. {$ Currnt = "class = 'current '";}
  157. Else
  158. {$ Currnt = "";}
  159. $ Str. = "pageUrl }={$ I} '{$ currnt}> $ I". "n ";

  160. }

  161. }
  162. }

  163. /*

  164. Page paging logic ends after the beginning and end
  165. */
  166. // Last page of The Next page
  167. If ($ this-> pageIndex = $ this-> totalPagesCount)
  168. {
  169. $ Str. = "n". "next page". "n ";
  170. $ Str. = "Last Page". "n ";

  171. } Else
  172. {
  173. $ Str. = "n ". "pageUrl} = ". ($ this-> pageIndex + 1 ). "'class = 'tids' title = 'next page'> next page ". "n ";
  174. $ Str. = "pageUrl }={$ this-> totalPagesCount} 'class = 'tids' title = 'Last page'> last page'." n ";
  175. }

  176. $ Str. ="

    ";
  177. Return $ str;
  178. }

  179. /**

  180. * Obtain an instance
  181. * @ Return
  182. */
  183. // Static public function getInstance (){
  184. // If (is_null (self: $ _ instance )){
  185. // Self: $ _ instance = new pager ();
  186. //}
  187. // Return self: $ _ instance;
  188. //}

  189. }
  190. ?>

3), php paging style file pager.css:

  1. Body, html {padding: 0px; margin: 0px; color: #333333; font-family: "", Arial, Lucida, Verdana, Helvetica, sans-serif; font-size: 12px; line-height: 150% ;}

  2. H1, h2, h3, h4, h5, h6, ul, li, dl, dt, dd, form, img, p, label {margin: 0; padding: 0; border: none; list-style-type: none ;}

  3. /** Front-end paging style **/

  4. . Pagination {margin: 10px 0 0; padding: 5px 0; text-align: rightright; height: 20px; line-height: 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. current: link ,. pagination. current: visited {border: 1px solid # dedede; color: # fff; background-color: # ff6600; background-image: none; border: # ff6600 solid 1px ;}
  9. . Pagination. selectBar {border: # dedede solid 1px; font-size: 12px; width: 95px; height: 21px; line-height: 21px; margin-left: 10px; display: inline}
  10. . Pagination a. tips {_ padding: 4px 7px 1px ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.