Php paging code, supports pseudo-static php paging class

Source: Internet
Author: User
Php paging code, supports pseudo-static php paging class

  1. Class Page {
  2. Protected $ each_disNums; // Number of Entries displayed on each page
  3. Protected $ nums; // total number of entries
  4. Protected $ current_page; // the currently selected page
  5. Protected $ sub_pages; // Number of pages displayed each time
  6. Protected $ pageNums; // total number of pages
  7. Protected $ page_array = array (); // used to construct an array of pagination
  8. Protected $ subPage_link; // The link of each page
  9. Protected $ subPage_type; // display page type
  10. Protected $ houz; // suffix
  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, $ houz = ''){
  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-> show_SubPages ($ subPage_type );
  36. $ This-> houz = $ houz;
  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
  85. $ Current_array [$ I] = $ I + 1;
  86. }
  87. } Elseif ($ this-> current_page <= $ this-> pageNums & $ this-> current_page> $ this-> pageNums-$ this-> sub_pages + 1 ){
  88. For ($ I = 0; $ I
  89. $ Current_array [$ I] = ($ this-> pageNums)-($ this-> sub_pages) + 1 + $ I;
  90. }
  91. } Else {
  92. For ($ I = 0; $ I
  93. $ Current_array [$ I] = $ this-> current_page-2 + $ I;
  94. }
  95. }
  96. }
  97. Return $ current_array;
  98. }
  99. /*
  100. Construct normal mode paging
  101. 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]
  102. */Bbs.it-home.org
  103. Function subPageCss1 (){
  104. $ SubPageCss1Str = "";
  105. $ SubPageCss1Str. = "total". $ this-> nums. "records ,";
  106. $ SubPageCss1Str. = "displayed on each page". $ this-> each_disNums ,";
  107. $ SubPageCss1Str. = "current section". $ this-> current_page. "/". $ this-> pageNums. "page ";
  108. If ($ this-> current_page> 1 ){
  109. $ FirstPageUrl = $ this-> subPage_link. "1". $ this-> houz;
  110. $ PrewPageUrl = $ this-> subPage_link. ($ this-> current_page-1). $ this-> houz;
  111. $ SubPageCss1Str. = "[Homepage]";
  112. $ SubPageCss1Str. = "[previous page]";
  113. } Else {
  114. $ SubPageCss1Str. = "[Homepage]";
  115. $ SubPageCss1Str. = "[previous page]";
  116. }
  117. If ($ this-> current_page <$ this-> pageNums ){
  118. $ LastPageUrl = $ this-> subPage_link. $ this-> pageNums. $ this-> houz;
  119. $ NextPageUrl = $ this-> subPage_link. ($ this-> current_page + 1). $ this-> houz;
  120. $ SubPageCss1Str. = "[Next Page]";
  121. $ SubPageCss1Str. = "[last page]";
  122. } Else {
  123. $ SubPageCss1Str. = "[Next Page]";
  124. $ SubPageCss1Str. = "[last page]";
  125. }
  126. Return $ subPageCss1Str;
  127. }
  128. /*
  129. Create pagination in classic mode
  130. Current page 1/453 [Homepage] [Previous Page] 1 2 3 4 5 6 7 8 9 10 [Next Page] [last page]
  131. */
  132. Function subPageCss2 (){
  133. $ SubPageCss2Str = "";
  134. $ SubPageCss2Str. = "total [". $ this-> nums. "] Current section ". $ this-> current_page. "/". $ this-> pageNums. "page ";
  135. If ($ this-> current_page> 1 ){
  136. $ FirstPageUrl = $ this-> subPage_link. "1". $ this-> houz;
  137. $ PrewPageUrl = $ this-> subPage_link. ($ this-> current_page-1). $ this-> houz;
  138. $ SubPageCss2Str. = "[Homepage]";
  139. $ SubPageCss2Str. = "[previous page]";
  140. } Else {
  141. $ SubPageCss2Str. = "[Homepage]";
  142. $ SubPageCss2Str. = "[previous page]";
  143. }
  144. $ A = $ this-> construct_num_Page ();
  145. For ($ I = 0; $ I
  146. $ S = $ a [$ I];
  147. If ($ s ==$ this-> current_page ){
  148. $ SubPageCss2Str. = "[". $ s. "]";
  149. } Else {
  150. $ Url = $ this-> subPage_link. $ s. $ this-> houz;
  151. $ SubPageCss2Str. = "[". $ s. "]";
  152. }
  153. }
  154. If ($ this-> current_page <$ this-> pageNums ){
  155. $ LastPageUrl = $ this-> subPage_link. $ this-> pageNums. $ this-> houz;
  156. $ NextPageUrl = $ this-> subPage_link. ($ this-> current_page + 1). $ this-> houz;
  157. $ SubPageCss2Str. = "[Next Page]";
  158. $ SubPageCss2Str. = "[last page]";
  159. } Else {
  160. $ SubPageCss2Str. = "[Next Page]";
  161. $ SubPageCss2Str. = "[last page]";
  162. }
  163. Return $ subPageCss2Str;
  164. }
  165. /*
  166. Construct ajax pagination in classic mode
  167. Current page 1/453 [Homepage] [Previous Page] 1 2 3 4 5 6 7 8 9 10 [Next Page] [last page]
  168. */
  169. Function subPageCss3 ($ fun = '', $ v = 'n '){
  170. $ SubPageCss2Str = "";
  171. $ SubPageCss2Str. = "total [". $ this-> nums. "] Current section ". $ this-> current_page. "/". $ this-> pageNums. "page ";
  172. If ($ this-> current_page> 1 ){
  173. // $ FirstPageUrl = $ this-> subPage_link. "1 ";
  174. $ PrewPageUrl = $ this-> current_page-1;
  175. $ SubPageCss2Str. = "[Homepage]";
  176. $ SubPageCss2Str. = "[previous page]";
  177. } Else {
  178. $ SubPageCss2Str. = "[Homepage]";
  179. $ SubPageCss2Str. = "[previous page]";
  180. }
  181. $ A = $ this-> construct_num_Page ();
  182. For ($ I = 0; $ I
  183. $ S = $ a [$ I];
  184. If ($ s ==$ this-> current_page ){
  185. $ SubPageCss2Str. = "[$ s]";
  186. } Else {
  187. $ SubPageCss2Str. = "[$ s]";
  188. }
  189. }
  190. If ($ this-> current_page <$ this-> pageNums ){
  191. $ LastPageUrl = $ this-> pageNums;
  192. $ NextPageUrl = $ this-> current_page + 1;
  193. $ SubPageCss2Str. = "[Next Page]";
  194. $ SubPageCss2Str. = "[last page]";
  195. } Else {
  196. $ SubPageCss2Str. = "[Next Page]";
  197. $ SubPageCss2Str. = "[last page]";
  198. }
  199. Return $ subPageCss2Str;
  200. }
  201. }
  202. ?>

Usage: instantiate this page class, $ list = new Page (how many pieces of data per page, total amount of data, current Page, used to construct an array of pages, each page link, display the type and suffix of the Page. for example, $ list = new page (, '/zjjz/', '); echo $ Page = $ list-> subPageCss2 (); it will be displayed: the current page 1/100 [Homepage] [Previous Page] 1 2 3 4 5 6 7 8 9 10 [Next Page] [last Page] each connection is/zjjz/1.html, /zjjz/2.html ....... You can combine the links of each page as needed to achieve pseudo-static.

While ajax paging is

$ List = new Page ($ pagesize, $ areaAllNumber, $ current_page, 10, ", 3); $ url = $ val1 .','. $ val2; // The value to be passed in the js function to be triggered. $ page = $ list-> subPageCss3 ('checkproducts', $ url ); // The first parameter is the js function to be triggered. To achieve the ajax paging effect.

There is also a subPageCss1 that contains a total of 4523 records, each page shows 10, the current 1/453 page [Homepage] [Previous Page] [Next Page] [last Page] this simple style, it also supports pseudo-static.

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.