Using the limit attribute of SQL is not difficult for MySQL databases.

Source: Internet
Author: User

This article describes how to correctly use the limit attribute of SQL to operate MySQL databases. If you are interested in the limit attribute of SQL, you can use the following articles to learn more about it.

Use the limit attribute of SQL for MySQL (the best combination with PHP) Databases

 
 
  1. & Lt ;? PHP
  2. Function pagetorecord ($ page, $ pagecounts ){
  3. $ Result = ($ page-1) * $ pagecounts;
  4. Return $ result;
  5. }
  6. Function pagech ($ page, $ j ){
  7. If ($ j = 1 ){
  8. $ P = $ page + 1 ;}
  9. Else {
  10. $ P = $ page-1 ;}
  11. Return $ p;
  12. }
  13. $ Pagecounts = 20;
  14. If ($ startpage ){
  15. $ Startpage = $ startpage;
  16. }
  17. Else {
  18. $ Startpage = 1;
  19. }
  20. $ Sqltr = "select * from main order by sm limit". pagetorecord ($ startpage, $ pagecounts). ",". $ pagecounts;
  21. $ Connect = MySQL (the best combination with PHP) _ connect ("localhost", "http", "something ");
  22. $ Select = MySQL (the best combination with PHP) _ select_db ('book', $ connect );
  23. $ Query = MySQL (the best combination with PHP) _ query ('select count (*) as total from main', $ connect );
  24. $ Totalrecord = MySQL (the best combination with PHP) _ result ($ query, 0, "total ");
  25. $ Query = MySQL (the best combination with PHP) _ query ($ sqltr, $ connect );
  26. Echo "& lt; table border = 1 cellpadding = 0 cellspacing = 0 & gt ;";
  27. Echo "& lt; tr & gt; & lt; td & gt; No. & lt;/td & gt; & lt; td & gt; standard account & lt; /td & gt; & lt; td & gt; Title & lt;/td & gt; & lt; td & gt; Press & lt;/td & gt; & lt; td & gt; pricing & lt;/td & gt; & lt;/tr & gt ;";
  28. $ I = 1;
  29. While ($ array = MySQL (the best combination with PHP) _ fetch_array ($ query )){
  30. Printf ("& lt; tr & gt; & lt; td & gt; % d & lt;/td & gt; & lt; td & gt; % s & lt; /td & gt; & lt; td & gt; % s & lt;/td & gt; & lt; td & gt; % f & lt;/td & gt; & lt;/tr & gt ;",
  31. $ I, $ array [bzsh], $ array [sm], $ array [cbs], $ array [dj]);
  32. $ I ++;
  33. }
  34. Echo "& lt;/table & gt ;";
  35. Echo "& lt; hr & gt ;";
  36. MySQL (the best combination with PHP) _ close ($ connect );
  37. If (0 = $ totalrecord % $ pagecounts ){
  38. $ Totalpage = floor ($ totalrecord/$ pagecounts );}
  39. Else {
  40. $ Totalpage = floor ($ totalrecord/$ pagecounts) + 1;
  41. }
  42. // Echo $ sqltr;
  43. If ($ startpage = 1 ){
  44. If ($ totalpage & gt; 1 ){
  45. Echo "Homepage ";
  46. Echo "Previous Page ";
  47. Echo "& lt; a href =.../". basename ($ PHP_SELF )."? Startpage = ". pagech ($ startpage, 1)." & gt; next page & lt;/a & gt ;";
  48. Echo "& lt; a href =.../". basename ($ PHP_SELF )."? Startpage = ". $ totalpage." & gt; last page & lt;/a & gt; Total ". $ totalpage." Page ". $ startpage." Page ";
  49. }
  50. Else {
  51. Echo "Homepage ";
  52. Echo "Previous Page ";
  53. Echo "next page ";
  54. Echo "last page ";
  55. }
  56. }
  57. Elseif ($ startpage ==$ totalpage ){
  58. Echo "& lt; a href =.../". basename ($ PHP_SELF )."? Startpage = 1 & gt; homepage & lt;/a & gt ;";
  59. Echo "& lt; a href =.../". basename ($ PHP_SELF )."? Startpage = ". pagech ($ startpage,-1)." & gt; Previous Page & lt;/a & gt ;";
  60. Echo "next page ";
  61. Echo "End page". $ totalpage. "Page". $ startpage. "Page ";
  62. }
  63. Else {
  64. Echo "& lt; a href =.../". basename ($ PHP_SELF )."? Startpage = 1 & gt; homepage & lt;/a & gt ;";
  65. Echo "& lt; a href =.../". basename ($ PHP_SELF )."? Startpage = ". pagech ($ startpage,-1)." & gt; Previous Page & lt;/a & gt ;";
  66. Echo "& lt; a href =.../". basename ($ PHP_SELF )."? Startpage = ". pagech ($ startpage, 1)." & gt; next page & lt;/a & gt ;";
  67. Echo "& lt; a href =.../". basename ($ PHP_SELF )."? Startpage = ". $ totalpage." & gt; last page & lt;/a & gt; Total ". $ totalpage." Page ". $ startpage." Page ";
  68. }
  69. ? & Gt;

The above content is an introduction to the MySQL database using the limit attribute of SQL. I hope you will gain some benefits.

Related Article

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.