Php paging principle simple paging code summary

Source: Internet
Author: User
Php paging principle simple paging code summary

  1. // Determine the number of entries displayed on each page

  2. // Count (*) queries the total number of items
  3. // Calculate the total number of pages ceil ()
  4. // Judge $ _ GET and assign a value to the current page number
  5. // Mysql Query limit (current page number-1) * number of entries per page, number of entries per page
  6. // If the total number of items is not empty, loop mysql_fetch_array ()
  7. // $ _ SERVER ['php _ SELF ']
  8. // Previous page? Page = current page-1
  9. // Next page? Page = current page + 1
  10. // Edit: bbs.it-home.org
  11. Include ("conn. php ");
  12. $ Perpagenum = 3;
  13. $ Total = mysql_fetch_array (mysql_query ("select count (*) FROM message "));
  14. $ Total = $ total [0];
  15. $ Totalpage = ceil ($ Total/$ perpagenum );

  16. If (! Isset ($ _ GET ['Page']) |! Intval ($ _ GET ['Page']) | $ _ GET ['Page']> $ Totalpage ){

  17. $ Page = 1;
  18. } Else {
  19. $ Page = $ _ GET ['Page'];
  20. }

  21. $ Start = ($ page-1) * $ perpagenum;

  22. $ SQL = "SELECT * FROM message ORDER BY id DESC LIMIT $ start, $ perpagenum ";
  23. $ Result = mysql_query ($ SQL );
  24. $ Contents = mysql_fetch_array ($ result );
  25. ?>
  26. If ($ total ){
  27. }
  28. Do {
  29. $ User = $ contents ['user'];
  30. $ Contact = $ contents ['Contact '];
  31. $ Content = $ contents ['content'];
  32. $ Date = $ contents ['Date'];

  33. ?>

  34. // Start with php paging
  35. While ($ contents = mysql_fetch_array ($ result ));
  36. $ Per = $ page-1;
  37. $ Next = $ page + 1;
  38. Echo" There are a Total of ". $ Total." messages, each page ". $ perpagenum.", Total ". $ page."/". $ Totalpage." pages. ";
  39. If ($ page! = 1 ){
  40. Echo "homepage ".
  41. "Previous page ";
  42. }
  43. If ($ page! = $ Totalpage ){
  44. Echo "next page ";
  45. Echo "last page ";
  46. }
  47. ?>
  48. }
  49. ?>
  50. Nickname: Posted on:

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.