PHP Paging class with a variety of paging methods

Source: Internet
Author: User
  1. Class PAGE {

  2. Class start
  3. /********************************************************
  4. * Total number of $total records
  5. * $pageNum the number of bars displayed per page
  6. * $url = ' link
  7. * $page->startpage (display categorical statistics, character classification/digital paging, jump);
  8. * $page->startpage (true/false, True/false, True/false);
  9. * Site http://bbs.it-home.org
  10. *********************************************************/
  11. Private $total; Total Records
  12. Private $pageNum; Number of displays per page
  13. Private $page; Current page
  14. Private $pages; Total number of pages
  15. Private $url; Page URL
  16. Private $Aque; URL parameters
  17. /* Constructor function */
  18. Public Function PAGE ($total, $pageNum, $url = '? ') {
  19. $this->total = $total; The total number of records.
  20. $this->pagenum = $pageNum; The number of displays per page.
  21. $this->url = $this->strsift ($url); Determines whether the value of the hash is legal.
  22. $this->aque = $_get; The parameters that the page originally passed.
  23. $this->page = $this->strsift ($_get[' page '); Current page get (global variable) mode parameter, current page number.
  24. $this->page = is_numeric ($this->page)? $this->page:1; When the current page number is not a number, it is set to 1.
  25. $this->pages = ceil ($total/$pageNum); Total pages.
  26. if ($this->page<1) $this->page = 1; When the page number is less than 1 o'clock, set it to 1.
  27. if ($this->page> $this->pages) $this->page = $this->pages; When the page number is greater than the maximum page number, it is set to the maximum page number.
  28. }
  29. /******************
  30. * Pagination Method
  31. *******************/
  32. function StartPage ($str, $view =true, $jump =true) {
  33. if ($view ==true) $PageStr. = $this->getcount (); Paging statistics
  34. if ($str = = ' str ') $PageStr. = $this->getpagestr (); Select the form of a character page
  35. else $PageStr. = $this->getpagenum (); Select the form of a digital page
  36. if ($jump ==true) $PageStr. = $this->jumpselect (); Jump
  37. return $PageStr;
  38. }

  39. /**********************************************

  40. * Display statistics. Format: Total 5 records page: 2/3
  41. ***********************************************/
  42. function GetCount () {
  43. $COUNTSTR = "Total ". $this->total. " Records page: ". $this->page." /". $this->pages." ";
  44. return $CountStr;
  45. }

  46. /***********************************************

  47. * Paging format one: First previous next last page
  48. ************************************************/
  49. function Getpagestr () {
  50. $url = $this->url; Get URL
  51. Handling of URL parameters: The key to the array is the URL variable, and the value of the array is the value of the URL variable.
  52. foreach ($this->aque as $key = + $val) {
  53. Switch ($key) {
  54. Case "page":
  55. $Next = $val + 1;
  56. $Prev = $val-1;
  57. Break
  58. Default
  59. $Sque. = "& $key =". $this->strsift ($val);
  60. }
  61. }
  62. if ($Next ==0) $Next = 2;
  63. Home previous Page
  64. Switch ($this->page) {
  65. Case $this->page<=1:
  66. $pagestr. = "Home";
  67. $pagestr. = "Previous page";
  68. Break
  69. Default
  70. $pagestr. = "Home";
  71. $pagestr. = "Previous page";
  72. }
  73. Next last Page
  74. Switch ($this->page) {
  75. Case $this->page>= $this->pages:
  76. $pagestr. = "Next page";
  77. $pagestr. = "Last";
  78. Break
  79. Default
  80. $pagestr. = "Next page";
  81. $pagestr. = "Pages$sque ' > Last";
  82. }
  83. Returns the paging string.
  84. return $pagestr;
  85. }

  86. /***********************************************************

  87. * Page Format: A total of 4,307 records page: 1/72 1 2 3 4 5 6 7 8 9 10
  88. ************************************************************/
  89. function Getpagenum () {
  90. $url = $this->url;
  91. Handling of URL parameters: The key to the array is the URL variable, and the value of the array is the value of the URL variable.
  92. foreach ($this->aque as $key = + $val) {
  93. Switch ($key) {
  94. Case $key! = "page":
  95. $Sque. = "& $key =". $this->strsift ($val);
  96. }
  97. }
  98. Switch ($this->pages) {
  99. The total number of pages is greater than 12 pages:
  100. Case $this->pages>12:
  101. Pagination Digital Front:< <<
  102. Switch ($this->page) {
  103. Case $this->page>1:
  104. $pagestr. = "<";
  105. $pagestr. = "page-1). $Sque." ' ><< ";
  106. Break
  107. Default
  108. $pagestr. = "<";
  109. $pagestr. = "<<";
  110. }
  111. Number of pages: 1 2 3 4 5 6 current page left 6 pagination links, 6 pagination links on the right.
  112. for ($i = $this->page-6; $i <= $this->page+6; $i + +) {
  113. if ($i > $this->pages) break;
  114. if ($i = = $this->page) $pagestr. = $i. " ";
  115. ElseIf ($i >=1) $pagestr. = "$i";
  116. }
  117. After paging number: > >>
  118. Switch ($this->page) {
  119. Case $this->page< $this->pages:
  120. $pagestr. = "page+1). $Sque." ' >>> ";
  121. $pagestr. = "pages. $Sque." >> ";
  122. Break
  123. Default
  124. $pagestr. = ">";
  125. $pagestr. = ">>";
  126. }
  127. Break
  128. Default
  129. The total number of pages is less than 12 pages:
  130. for ($i =1; $i <= $this->pages; $i +) {
  131. Switch ($i) {
  132. Case $i = = $this->page:
  133. $pagestr. = $i. " ";
  134. Break
  135. Default
  136. $pagestr. = "$i";
  137. }
  138. }
  139. }
  140. Returns the paging string.
  141. return $pagestr;
  142. }
  143. /************************
  144. * Define jump pages. BEGIN
  145. *************************/
  146. function Jumpselect () {
  147. $url = $this->url;
  148. Handling of URL parameters: The key to the array is the URL variable, and the value of the array is the value of the URL variable.
  149. foreach ($this->aque as $key = + $val) {
  150. if ($key! = "page") $Sque. = "& $key =". $this->strsift ($val);
  151. }
  152. $SELECTSTR = "\ n
  153. $SelectStr. = "onchange=\" window.location= ' ". $url."? Page= ' +this.value+ ' ". $Sque." \ ">\n"; for ($i =1; $i <= $this->pages; $i + +) {if ($i = = $this->page) $selected = "selected"; Else $selected = ""; $SelectStr. = "$i \ n "; } $SelectStr. = "\ n";
  154. Returns the paging string.
  155. return $SelectStr;
  156. }

  157. /**********************************

  158. * Filter special characters.
  159. ***********************************/
  160. Private Function Strsift ($STR) {
  161. $str = Str_replace ("\" "," ", $str);
  162. $str = Str_replace ("'", "" ", $str);
  163. $str = Str_replace ("[Url=file://%22,%22%22, $str/]\\", "", $str [/url]);
  164. $str = str_replace ("\ \", "", $str);
  165. $str = Str_replace (":", "", $str);
  166. $str = Str_replace ("?", "" ", $str); Removal will appear "??".
  167. $str = Str_replace (">", "", $str);
  168. $str = Str_replace ("<", "", $str);
  169. $str = str_replace ("%", "", $str);
  170. $str = Str_replace ("*", "", $str);
  171. $str = Str_replace ("&", "", $str);
  172. $str = Str_replace (".", "", $str);
  173. return $str;
  174. }

  175. Class End

  176. }
  177. ?>

Copy Code

Interested friends, can also refer to the following article: A good PHP page class code A useful PHP paging class

Paging style sheet:

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.