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
- & Lt ;? PHP
- Function pagetorecord ($ page, $ pagecounts ){
- $ Result = ($ page-1) * $ pagecounts;
- Return $ result;
- }
- Function pagech ($ page, $ j ){
- If ($ j = 1 ){
- $ P = $ page + 1 ;}
- Else {
- $ P = $ page-1 ;}
- Return $ p;
- }
- $ Pagecounts = 20;
- If ($ startpage ){
- $ Startpage = $ startpage;
- }
- Else {
- $ Startpage = 1;
- }
- $ Sqltr = "select * from main order by sm limit". pagetorecord ($ startpage, $ pagecounts). ",". $ pagecounts;
- $ Connect = MySQL (the best combination with PHP) _ connect ("localhost", "http", "something ");
- $ Select = MySQL (the best combination with PHP) _ select_db ('book', $ connect );
- $ Query = MySQL (the best combination with PHP) _ query ('select count (*) as total from main', $ connect );
- $ Totalrecord = MySQL (the best combination with PHP) _ result ($ query, 0, "total ");
- $ Query = MySQL (the best combination with PHP) _ query ($ sqltr, $ connect );
- Echo "& lt; table border = 1 cellpadding = 0 cellspacing = 0 & gt ;";
- 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 ;";
- $ I = 1;
- While ($ array = MySQL (the best combination with PHP) _ fetch_array ($ query )){
- 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 ;",
- $ I, $ array [bzsh], $ array [sm], $ array [cbs], $ array [dj]);
- $ I ++;
- }
- Echo "& lt;/table & gt ;";
- Echo "& lt; hr & gt ;";
- MySQL (the best combination with PHP) _ close ($ connect );
- If (0 = $ totalrecord % $ pagecounts ){
- $ Totalpage = floor ($ totalrecord/$ pagecounts );}
- Else {
- $ Totalpage = floor ($ totalrecord/$ pagecounts) + 1;
- }
- // Echo $ sqltr;
- If ($ startpage = 1 ){
- If ($ totalpage & gt; 1 ){
- Echo "Homepage ";
- Echo "Previous Page ";
- Echo "& lt; a href =.../". basename ($ PHP_SELF )."? Startpage = ". pagech ($ startpage, 1)." & gt; next page & lt;/a & gt ;";
- Echo "& lt; a href =.../". basename ($ PHP_SELF )."? Startpage = ". $ totalpage." & gt; last page & lt;/a & gt; Total ". $ totalpage." Page ". $ startpage." Page ";
- }
- Else {
- Echo "Homepage ";
- Echo "Previous Page ";
- Echo "next page ";
- Echo "last page ";
- }
- }
- Elseif ($ startpage ==$ totalpage ){
- Echo "& lt; a href =.../". basename ($ PHP_SELF )."? Startpage = 1 & gt; homepage & lt;/a & gt ;";
- Echo "& lt; a href =.../". basename ($ PHP_SELF )."? Startpage = ". pagech ($ startpage,-1)." & gt; Previous Page & lt;/a & gt ;";
- Echo "next page ";
- Echo "End page". $ totalpage. "Page". $ startpage. "Page ";
- }
- Else {
- Echo "& lt; a href =.../". basename ($ PHP_SELF )."? Startpage = 1 & gt; homepage & lt;/a & gt ;";
- Echo "& lt; a href =.../". basename ($ PHP_SELF )."? Startpage = ". pagech ($ startpage,-1)." & gt; Previous Page & lt;/a & gt ;";
- Echo "& lt; a href =.../". basename ($ PHP_SELF )."? Startpage = ". pagech ($ startpage, 1)." & gt; next page & lt;/a & gt ;";
- Echo "& lt; a href =.../". basename ($ PHP_SELF )."? Startpage = ". $ totalpage." & gt; last page & lt;/a & gt; Total ". $ totalpage." Page ". $ startpage." Page ";
- }
- ? & Gt;
The above content is an introduction to the MySQL database using the limit attribute of SQL. I hope you will gain some benefits.