Php + mysql paging query code (mysql paging example)

Source: Internet
Author: User
Php + mysql paging query code (mysql paging example)

  1. /*
  2. * Php paging query code
  3. *
  4. */
  5. $ Perpagenum = 10; // defines the number of entries displayed on each page.
  6. $ Total = mysql_fetch_array (mysql_query ("select count (*) from a"); // query the total number of data records in the database
  7. $ Total = $ total [0]; //
  8. $ Totalpage = ceil ($ Total/$ perpagenum); // go to the house and get the integer
  9. If (! Isset ($ _ GET ['Page']) |! Intval ($ _ GET ['Page']) | $ _ GET ['Page']> $ Totalpage) // Four possible page states
  10. {
  11. $ Page = 1;
  12. }
  13. Else
  14. {
  15. $ Page = $ _ GET ['Page']; // if the preceding conditions are not met, the page value is $ _ GET ['Page']
  16. }
  17. $ Startnum = ($ page-1) * $ perpagenum; // number of start entries
  18. $ SQL = "select * from a order by id limit $ startnum, $ perpagenum"; // query the number of required entries
  19. Echo $ SQL ."
  20. ";
  21. $ Rs = mysql_query ($ SQL );
  22. $ Contents = mysql_fetch_array ($ rs );
  23. If ($ total) if $ total is not empty, execute the following statement:
  24. {
  25. Do
  26. {
  27. $ Id = $ contents ['id'];
  28. $ Name = $ contents ['name'];
  29. ?>
  30. Id:
  31. Name:
  32. }
  33. While ($ contents = mysql_fetch_array ($ rs); // do... while
  34. $ Per = $ page-1; // Previous page
  35. $ Next = $ page + 1; // next page
  36. Echo" A Total of ". $ Total." records, each page ". $ perpagenum.", Total ". $ Totalpage." page ";
  37. If ($ page! = 1)
  38. {
  39. Echo "homepage ";
  40. Echo "previous page ";
  41. }
  42. If ($ page! = $ Totalpage)
  43. {
  44. Echo "next page ";
  45. Echo "last page
  46. ";
  47. }
  48. }
  49. Else outputs No message if $ total is null
  50. {
  51. Echo" No message ";
  52. }
  53. ?>

Recommended reading:
  • Php and ajax without refreshing paging code
  • Php article paging implementation code
  • Php limit paging code
  • Php paging class with multiple paging methods
  • Php paging code for the previous and next pages
  • Top 10 pages and top 10 pages of php paging code
  • Example of simple php paging code
  • A good php paging code
  • One paging function: next page on the previous page
  • A handy php paging class
  • Php long article paging code
  • A Practical php paging class
  • Quick php paging

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.