Useful PHP Paging class, a variety of page styles

Source: Internet
Author: User
Copy Code
  1. Class subpages{
  2. Private $each _disnums;//The number of entries displayed per page
  3. private $nums;//Total number of entries
  4. Private $current _page;//the currently selected page
  5. Private $sub _pages;//pages per display
  6. private $pageNums;//Total pages
  7. private $point;//Total pages
  8. Private $page _array = Array ();//the array used to construct pagination
  9. Private $subPage _link;//links for each page
  10. Private $subPage _type;//shows the type of paging
  11. / *
  12. __construct is a subpages constructor that is used to run automatically when a class is created.
  13. @ $each _disnums The number of entries displayed per page
  14. @nums Total number of entries
  15. @current_num the currently selected page
  16. @sub_pages number of pages per display
  17. @subPage_link links for each page
  18. @subPage_type show the type of paging
  19. When @subpage_type=1 is the normal paging mode
  20. Example: A total of 4,523 records, each page shows 10, the current 1th/453 page [first] [prev] [next] [last page]
  21. When @subpage_type=2 is a classic page-out style
  22. Example: Current 1th 453 page [first] [prev] 1 2 3 4 5 6 7 8 9 10 [next] [last]
  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. The __destruct destructor is called when the class is not in use, and the function is used to free 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 inside the constructor. and used to determine what kind of paging to show.
  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 created the paging.
  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 the function used to construct the displayed entry
  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. Constructing the pagination of Classic mode
  101. Current 1th/453 [first] [prev] 1 2 3 4 5 6 7 8 9 10 [next] [last]
  102. * /
  103. function SubPageCss2 () {
  104. $subPageCss 2str= "";
  105. A total of 246 page 2347 article business Information
  106. $subPageCss 2str.= " current Section ". $this->current_page. " /". $this->pagenums. page total. $this->nums." Merchant Information ";
  107. $subPageCss 2str.= "Current section". $this->current_page. " /". $this->pagenums." Page ";
  108. if ($this->current_page > 1) {
  109. $FIRSTPAGEURL = $this->subpage_link. " 1 "." #zkfb_shop ";
  110. $PREWPAGEURL = $this->subpage_link. ($this->current_page-1). $this->point;
  111. Home previous Page
  112. $subPageCss 2str.= "Home";
  113. $SUBPAGECSS 2str.= "Previous page";
  114. }else {
  115. $subPageCss 2str.= "Home";
  116. $SUBPAGECSS 2str.= "Previous page";
  117. }
  118. $a = $this->construct_num_page ();
  119. for ($i =0; $i
  120. $s = $a [$i];
  121. if ($s = = $this->current_page) {
  122. $subPageCss 2str.= "[". $s. "]";
  123. $subPageCss 2str.= "". $s. "";
  124. }else{
  125. $url = $this->subpage_link. $s. $this->point;
  126. 2
  127. $subPageCss 2str.= "". $s. "";
  128. $subPageCss 2str.= "[". $s. "]";
  129. }
  130. }
  131. if ($this->current_page < $this->pagenums) {
  132. $LASTPAGEURL = $this->subpage_link. $this->pagenums. $this->point;
  133. $NEXTPAGEURL = $this->subpage_link. ($this->current_page+1). $this->point;
  134. Next last Page
  135. $subPageCss 2str.= "Next page";
  136. $subPageCss 2str.= "Last";
  137. }else {
  138. $subPageCss 2str.= "Next page";
  139. $subPageCss 2str.= "Last";
  140. }
  141. echo $subPageCss 2Str;
  142. }
  143. }
  144. ?>
Copy Code
  • 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.