Php paging class code example, which can be used in the php Framework

Source: Internet
Author: User
Php paging class code example, which can be used in the php Framework

  1. // Php paging code
  2. Class page {
  3. Public $ page; // current page
  4. Public $ pagenum; // Number of pages
  5. Public $ pagesize; // number of entries per page
  6. Public function _ construct ($ count, $ pagesize ){
  7. $ This-> pagenum = ceil ($ count/$ pagesize );
  8. $ This-> pagesize = $ pagesize;
  9. $ This-> page = (isset ($ _ GET ['P']) & $ _ GET ['P']> 0 )? Intval ($ _ GET ['P']): 1;
  10. }
  11. /**
  12. * Get the get parameter passed after the url
  13. */
  14. Public function getUrl (){
  15. $ Url = 'index. php? '. Http_build_query ($ _ GET );
  16. $ Url = preg_replace ('/[?, &] P = (\ w) +/', '', $ url );
  17. $ Url. = (strpos ($ url ,"? ") = False )? '? ':'&';
  18. Return $ url;
  19. }
  20. /**
  21. * Retrieve html pages
  22. */
  23. Public function getPage (){
  24. $ Url = $ this-> getUrl ();
  25. $ Start = $ this-> page-5;
  26. $ Start = $ start> 0? $ Start: 1;
  27. $ End = $ start + 9;
  28. $ End = $ end <$ this-> pagenum? $ End: $ this-> pagenum;
  29. $ Pagestr = '';
  30. If ($ this-> page> 5 ){
  31. $ Pagestr = "homepage ";
  32. }
  33. If ($ this-> page! = 1 ){
  34. $ Pagestr. = "page-1)."> Previous page ";
  35. }
  36. For ($ I = $ start; $ I <= $ end; $ I ++ ){
  37. $ Pagestr. = "". $ I ."";
  38. }
  39. If ($ this-> page! = $ This-> pagenum ){
  40. $ Pagestr. = "page + 1)."> Next page ";
  41. }
  42. If ($ this-> page + 5 <$ this-> pagenum ){
  43. $ Pagestr. = "pagenum."> last page ";
  44. }
  45. Return $ pagestr;
  46. } // Edit: bbs.it-home.org
  47. }
  48. // Paging code test
  49. $ Page = new page (100,10 );
  50. $ Str = $ page-> getPage ();
  51. Echo $ str;
  52. ?>

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.