Practical php paging class, multiple paging styles

Source: Internet
Author: User
Practical php paging class, multiple paging styles

  1. Class SubPages {
  2. Private $ each_disNums; // Number of Entries displayed on each page
  3. Private $ nums; // The total number of items.
  4. Private $ current_page; // the currently selected page
  5. Private $ sub_pages; // The number of pages displayed each time
  6. Private $ pageNums; // total number of pages
  7. Private $ point; // The total number of pages.
  8. Private $ page_array = array (); // used to construct an array of pagination
  9. Private $ subPage_link; // The link of each page
  10. Private $ subPage_type; // type of the display page
  11. /*
  12. _ Construct is the SubPages Constructor used to automatically run classes when they are created.
  13. @ $ Each_disNums number of entries per page
  14. @ Nums total number of entries
  15. @ Current_num the selected page
  16. @ Sub_pages the number of pages displayed each time
  17. @ SubPage_link: the link of each page
  18. @ SubPage_type: type of the display page
  19. Normal paging mode when @ subPage_type = 1
  20. 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]
  21. Classic paging style when @ subPage_type = 2
  22. Example: current page 1/453 [Homepage] [Previous Page] 1 2 3 4 5 6 7 8 9 10 [Next Page] [last page]
  23. */
  24. Function _ construct ($ each_disNums, $ nums, $ current_page, $ sub_pages, $ subPage_link, $ subPage_type, $ point ){
  25. $ This-> each_disNums = intval ($ each_disNums );
  26. $ This-> nums = intval ($ nums );
  27. If (! $ Current_page ){
  28. $ This-> current_page = 1;
  29. } Else {
  30. $ This-> current_page = intval ($ current_page );
  31. }
  32. $ This-> sub_pages = intval ($ sub_pages );
  33. $ This-> pageNums = ceil ($ nums/$ each_disNums );
  34. $ This-> subPage_link = $ subPage_link;
  35. $ This-> point = $ point;
  36. $ This-> show_SubPages ($ subPage_type );
  37. // Echo $ this-> pageNums. "--". $ this-> sub_pages;
  38. }
  39. /*
  40. _ Destruct: a destructor called when the class is not in use. This function is used to release resources.
  41. */
  42. Function _ destruct (){
  43. Unset ($ each_disNums );
  44. Unset ($ nums );
  45. Unset ($ current_page );
  46. Unset ($ sub_pages );
  47. Unset ($ pageNums );
  48. Unset ($ page_array );
  49. Unset ($ subPage_link );
  50. Unset ($ subPage_type );
  51. }
  52. /*
  53. The show_SubPages function is used in the constructor. And used to determine what the page looks like
  54. */
  55. Function show_SubPages ($ subPage_type ){
  56. If ($ subPage_type = 1 ){
  57. $ This-> subPageCss1 ();
  58. } Elseif ($ subPage_type = 2 ){
  59. $ This-> subPageCss2 ();
  60. }
  61. }
  62. /*
  63. The function used to initialize the array that creates pagination.
  64. */
  65. Function initArray (){
  66. For ($ I = 0; $ I <$ this-> sub_pages; $ I ++ ){
  67. $ This-> page_array [$ I] = $ I;
  68. }
  69. Return $ this-> page_array;
  70. }
  71. /*
  72. Construct_num_Page this function is used to construct display entries
  73. Even if: [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
  74. */
  75. Function construct_num_Page (){
  76. If ($ this-> pageNums <$ this-> sub_pages ){
  77. $ Current_array = array ();
  78. For ($ I = 0; $ I <$ this-> pageNums; $ I ++ ){
  79. $ Current_array [$ I] = $ I + 1;
  80. }
  81. } Else {
  82. $ Current_array = $ this-> initArray ();
  83. If ($ this-> current_page <= 3 ){
  84. For ($ I = 0; $ I $ Current_array [$ I] = $ I + 1;
  85. }
  86. } Elseif ($ this-> current_page <= $ this-> pageNums & $ this-> current_page> $ this-> pageNums-$ this-> sub_pages + 1 ){
  87. For ($ I = 0; $ I $ Current_array [$ I] = ($ this-> pageNums)-($ this-> sub_pages) + 1 + $ I;
  88. }
  89. } Else {
  90. For ($ I = 0; $ I $ Current_array [$ I] = $ this-> current_page-2 + $ I;
  91. }
  92. }
  93. }
  94. Return $ current_array;
  95. }
  96. /*
  97. Create pagination in classic mode
  98. Current page 1/453 [Homepage] [Previous Page] 1 2 3 4 5 6 7 8 9 10 [Next Page] [last page]
  99. */
  100. Function subPageCss2 (){
  101. $ SubPageCss2Str = "";
  102. // Total246Page2347Seller information
  103. $ SubPageCss2Str. = "current". $ This-> current_page ."/". $ This-> pageNums ."Total pages". $ This-> nums ."Seller information ";
  104. // $ SubPageCss2Str. = "current number". $ this-> current_page. "/". $ this-> pageNums. "page ";
  105. If ($ this-> current_page> 1 ){
  106. $ FirstPageUrl = $ this-> subPage_link. "1". "# zkfb_shop ";
  107. $ PrewPageUrl = $ this-> subPage_link. ($ this-> current_page-1). $ this-> point;
  108. // Homepage previous page
  109. $ SubPageCss2Str. = "homepage ";
  110. $ SubPageCss2Str. = "previous page ";
  111. } Else {
  112. $ SubPageCss2Str. = "homepage ";
  113. $ SubPageCss2Str. = "previous page ";
  114. }
  115. $ A = $ this-> construct_num_Page ();
  116. For ($ I = 0; $ I $ S = $ a [$ I];
  117. If ($ s ==$ this-> current_page ){
  118. // $ SubPageCss2Str. = "[". $ s. "]";
  119. $ SubPageCss2Str. = "". $ s ."";
  120. } Else {
  121. $ Url = $ this-> subPage_link. $ s. $ this-> point;
  122. // 2
  123. $ SubPageCss2Str. = "". $ s ."";
  124. // $ SubPageCss2Str. = "[". $ s. "]";
  125. }
  126. }
  127. If ($ this-> current_page <$ this-> pageNums ){
  128. $ LastPageUrl = $ this-> subPage_link. $ this-> pageNums. $ this-> point;
  129. $ NextPageUrl = $ this-> subPage_link. ($ this-> current_page + 1). $ this-> point;
  130. // Last page of The Next page
  131. $ SubPageCss2Str. = "next page ";
  132. $ SubPageCss2Str. = "Last page ";
  133. } Else {
  134. $ SubPageCss2Str. = "next page ";
  135. $ SubPageCss2Str. = "Last page ";
  136. }
  137. Echo $ subPageCss2Str;
  138. }
  139. }
  140. ?>

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.