Php paging and calling methods

Source: Internet
Author: User
Php paging and calling methods

  1. /**

  2. * Php paging code
  3. * Edit: bbs.it-home.org
  4. */
  5. Class Page {
  6. Private $ total; // total records
  7. Private $ pagesize; // The number of entries displayed on each page
  8. Private $ limit; // limit
  9. Private $ page; // The current page number.
  10. Private $ pagenum; // the total page number.
  11. Private $ url; // address
  12. Private $ bothnum; // The number of numeric pages on both sides

  13. // Constructor initialization

  14. Public function _ construct ($ _ total, $ _ pagesize ){
  15. $ This-> total = $ _ total? $ _ Total: 1;
  16. $ This-> pagesize = $ _ pagesize;
  17. $ This-> pagenum = ceil ($ this-> total/$ this-> pagesize );
  18. $ This-> page = $ this-> setPage ();
  19. $ This-> limit = "LIMIT". ($ this-> page-1) * $ this-> pagesize. ", $ this-> pagesize ";
  20. $ This-> url = $ this-> setUrl ();
  21. $ This-> bothnum = 2;
  22. }

  23. // Interceptor

  24. Private function _ get ($ _ key ){
  25. Return $ this-> $ _ key;
  26. }

  27. // Obtain the current page number

  28. Private function setPage (){
  29. If (! Empty ($ _ GET ['Page']) {
  30. If ($ _ GET ['Page']> 0 ){
  31. If ($ _ GET ['Page']> $ this-> pagenum ){
  32. Return $ this-> pagenum;
  33. } Else {
  34. Return $ _ GET ['Page'];
  35. }
  36. } Else {
  37. Return 1;
  38. }
  39. } Else {
  40. Return 1;
  41. }
  42. }

  43. // Obtain the address

  44. Private function setUrl (){
  45. $ _ Url = $ _ SERVER ["REQUEST_URI"];
  46. $ _ Par = parse_url ($ _ url );
  47. If (isset ($ _ par ['query']) {
  48. Parse_str ($ _ par ['query'], $ _ query );
  49. Unset ($ _ query ['Page']);
  50. $ _ Url = $ _ par ['path']. '? '. Http_build_query ($ _ query );
  51. }
  52. Return $ _ url;
  53. } // Numeric Directory
  54. Private function pageList (){
  55. For ($ I = $ this-> bothnum; $ I >=1; $ I --){
  56. $ _ Page = $ this-> page-$ I;
  57. If ($ _ page <1) continue;
  58. $ _ Pagelist. = 'URL. '& page ='. $ _ page. '">'. $ _ page .'';
  59. }
  60. $ _ Pagelist. = ''. $ this-> page .'';
  61. For ($ I = 1; $ I <= $ this-> bothnum; $ I ++ ){
  62. $ _ Page = $ this-> page + $ I;
  63. If ($ _ page> $ this-> pagenum) break;
  64. $ _ Pagelist. = 'URL. '& page ='. $ _ page. '">'. $ _ page .'';
  65. }
  66. Return $ _ pagelist;
  67. }

  68. // Homepage

  69. Private function first (){
  70. If ($ this-> page> $ this-> bothnum + 1 ){
  71. Return 'URL. '"> 1 ...';
  72. }
  73. }

  74. // Previous Page

  75. Private function prev (){
  76. If ($ this-> page = 1 ){
  77. Return 'previous page ';
  78. }
  79. Return 'URL. '& page ='. ($ this-> page-1). '"> Previous page ';
  80. }

  81. // Next page

  82. Private function next (){
  83. If ($ this-> page ==$ this-> pagenum ){
  84. Return 'next page ';
  85. }
  86. Return 'URL. '& page ='. ($ this-> page + 1). '"> Next page ';
  87. }

  88. // Last Page

  89. Private function last (){
  90. If ($ this-> pagenum-$ this-> page> $ this-> bothnum ){
  91. Return '... url.' & page = '. $ this-> pagenum.' "> '. $ this-> pagenum .'';
  92. }
  93. }

  94. // Paging information

  95. Public function showpage (){
  96. $ _ Page. = $ this-> first ();
  97. $ _ Page. = $ this-> pageList ();
  98. $ _ Page. = $ this-> last ();
  99. $ _ Page. = $ this-> prev ();
  100. $ _ Page. = $ this-> next ();
  101. Return $ _ page;
  102. }
  103. }
  104. ?>

Paging style:

Instructions for use:

  1. $ _ Page = new Page ($ _ total, $ _ pagesize); // where $ _ total indicates the total number of data sets, and $ _ pagesize indicates the number displayed on each page.
  2. ?>

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.