Php paging class and paging function multiple paging styles for selection-php Tutorial

Source: Internet
Author: User
Multiple paging styles for php paging and paging functions

  1. /**

  2. * Page name: page_class.php
  3. */
  4. Class Page {
  5. Private $ each_disNums; // Number of Entries displayed on each page
  6. Private $ nums; // The total number of items.
  7. Private $ current_page; // the currently selected page
  8. Private $ sub_pages; // The number of pages displayed each time
  9. Private $ pageNums; // total number of pages
  10. Private $ page_array = array (); // used to construct an array of pagination
  11. Private $ subPage_link; // The link of each page
  12. /**
  13. *
  14. * _ Construct is the SubPages Constructor used to automatically run classes when they are created.
  15. * @ $ Each_disNums number of entries displayed on each page
  16. * @ Nums total number of entries
  17. * @ Current_num the selected page
  18. * @ Sub_pages the number of pages displayed each time
  19. * @ SubPage_link the link of each page
  20. * @ SubPage_type: type of the display page
  21. *
  22. * When @ subPage_type = 1, it is in normal paging mode.
  23. * Example: a total of 4523 records are displayed. 10 records are displayed on each page. Currently, page 1/453 [Homepage] [Previous Page] [Next Page] [last page]
  24. * The classic paging style is used when @ subPage_type = 2.
  25. * Example: current page 1/453 [Homepage] [Previous Page] 1 2 3 4 5 6 7 8 9 10 [Next Page] [last page]
  26. */
  27. Function Page ($ each_disNums, $ nums, $ current_page, $ sub_pages, $ subPage_link ){
  28. $ This-> each_disNums = intval ($ each_disNums );
  29. $ This-> nums = intval ($ nums );
  30. If (! $ Current_page ){
  31. $ This-> current_page = 1;
  32. } Else {
  33. $ This-> current_page = intval ($ current_page );
  34. }
  35. $ This-> sub_pages = intval ($ sub_pages );
  36. $ This-> pageNums = ceil ($ nums/$ each_disNums );
  37. $ This-> subPage_link = $ subPage_link;
  38. }
  39. /**
  40. * Take Care of earlier versions
  41. */
  42. Function _ construct ($ each_disNums, $ nums, $ current_page, $ sub_pages, $ subPage_linke ){
  43. $ This-> Page ($ each_disNums, $ nums, $ current_page, $ sub_pages, $ subPage_link );
  44. }

  45. /*

  46. _ Destruct: a destructor called when the class is not in use. This function is used to release resources.
  47. */
  48. Function _ destruct (){
  49. Unset ($ each_disNums );
  50. Unset ($ nums );
  51. Unset ($ current_page );
  52. Unset ($ sub_pages );
  53. Unset ($ pageNums );
  54. Unset ($ page_array );
  55. Unset ($ subPage_link );
  56. }

  57. /*

  58. The function used to initialize the array that creates pagination.
  59. */
  60. Function initArray (){
  61. For ($ I = 0; $ I <$ this-> sub_pages; $ I ++ ){
  62. $ This-> page_array [$ I] = $ I;
  63. }
  64. Return $ this-> page_array;
  65. }

  66. /*

  67. Construct_num_Page this function is used to construct display entries
  68. Even if: [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
  69. */
  70. Function construct_num_Page (){
  71. If ($ this-> pageNums <$ this-> sub_pages ){
  72. $ Current_array = array ();
  73. For ($ I = 0; $ I <$ this-> pageNums; $ I ++ ){
  74. $ Current_array [$ I] = $ I + 1;
  75. }
  76. } Else {
  77. $ Current_array = $ this-> initArray ();
  78. If ($ this-> current_page <= 3 ){
  79. For ($ I = 0; $ I <count ($ current_array); $ I ++ ){
  80. $ Current_array [$ I] = $ I + 1;
  81. }
  82. }
  83. Elseif ($ this-> current_page <= $ this-> pageNums & $ this-> current_page> $ this-> pageNums-$ this-> sub_pages + 1 ){
  84. For ($ I = 0; $ I <count ($ current_array); $ I ++ ){
  85. $ Current_array [$ I] = ($ this-> pageNums)-($ this-> sub_pages) + 1 + $ I;
  86. }
  87. } Else {
  88. For ($ I = 0; $ I <count ($ current_array); $ I ++ ){
  89. $ Current_array [$ I] = $ this-> current_page-2 + $ I;
  90. }
  91. }
  92. }

  93. Return $ current_array;

  94. }

  95. /*

  96. Construct normal mode paging
  97. A total of 4523 records are displayed. 10 records are displayed on each page. Currently, page 1/453 [Homepage] [Previous Page] [Next Page] [last page]
  98. */
  99. Function subPageCss1 (){
  100. $ SubPageCss1Str = "";
  101. $ SubPageCss1Str. = "total". $ this-> nums. "records ,";
  102. $ SubPageCss1Str. = "displayed on each page". $ this-> each_disNums ,";
  103. $ SubPageCss1Str. = "current section". $ this-> current_page. "/". $ this-> pageNums. "page ";
  104. If ($ this-> current_page> 1 ){
  105. $ FirstPageUrl = $ this-> subPage_link. "1 ";
  106. $ PrewPageUrl = $ this-> subPage_link. ($ this-> current_page-1 );
  107. $ SubPageCss1Str. = "[Homepage]";
  108. $ SubPageCss1Str. = "[previous page]";
  109. } Else {
  110. $ SubPageCss1Str. = "[Homepage]";
  111. $ SubPageCss1Str. = "[previous page]";
  112. }

  113. If ($ this-> current_page <$ this-> pageNums ){

  114. $ LastPageUrl = $ this-> subPage_link. $ this-> pageNums;
  115. $ NextPageUrl = $ this-> subPage_link. ($ this-> current_page + 1 );
  116. $ SubPageCss1Str. = "[Next Page]";
  117. $ SubPageCss1Str. = "[last page]";
  118. } Else {
  119. $ SubPageCss1Str. = "[Next Page]";
  120. $ SubPageCss1Str. = "[last page]";
  121. }

  122. Return $ subPageCss1Str;

  123. }

  124. /*

  125. Create pagination in classic mode
  126. Current page 1/453 [Homepage] [Previous Page] 1 2 3 4 5 6 7 8 9 10 [Next Page] [last page]
  127. */
  128. Function subPageCss2 (){
  129. $ SubPageCss2Str = "";
  130. $ SubPageCss2Str. = "current section". $ this-> current_page. "/". $ this-> pageNums. "page ";

  131. If ($ this-> current_page> 1 ){

  132. $ FirstPageUrl = $ this-> subPage_link. "1 ";
  133. $ PrewPageUrl = $ this-> subPage_link. ($ this-> current_page-1 );
  134. $ SubPageCss2Str. = "[Homepage]";
  135. $ SubPageCss2Str. = "[previous page]";
  136. } Else {
  137. $ SubPageCss2Str. = "[Homepage]";
  138. $ SubPageCss2Str. = "[previous page]";
  139. }

  140. $ A = $ this-> construct_num_Page ();

  141. For ($ I = 0; $ I <count ($ a); $ I ++ ){
  142. $ S = $ a [$ I];
  143. If ($ s ==$ this-> current_page ){
  144. $ SubPageCss2Str. = "[". $ s. "]";
  145. } Else {
  146. $ Url = $ this-> subPage_link. $ s;
  147. $ SubPageCss2Str. = "[". $ s. "]";
  148. }
  149. }

  150. If ($ this-> current_page <$ this-> pageNums ){

  151. $ LastPageUrl = $ this-> subPage_link. $ this-> pageNums;
  152. $ NextPageUrl = $ this-> subPage_link. ($ this-> current_page + 1 );
  153. $ SubPageCss2Str. = "[Next Page]";
  154. $ SubPageCss2Str. = "[last page]";
  155. } Else {
  156. $ SubPageCss2Str. = "[Next Page]";
  157. $ SubPageCss2Str. = "[last page]";
  158. }
  159. Return $ subPageCss2Str;
  160. }
  161. }

  162. // Test two different effects

  163. $ T = new Page (10,100, $ _ GET ['P'], 5, 'page _ class. php? P = ');
  164. Echo $ t-> subPageCss2 (); // call the classic paging function

  165. Echo"
    ";

  166. Echo $ t-> subPageCss1 (); // call a common paging function

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.