Detailed paging navigation ideas for PHP and MYSQL implementation and detailed paging ideas for mysql
Expected results
Ideas
SQL statement SELECT * FROM table LIMIT start end
From the MySql database
Procedure
Incoming page number p;
Retrieve data by page number php> mysql
Display Data + paging entries
Source code
Github Link
Notes
- The style of controls such as table, input, and button does not inherit the body. You need to redefine the following:
input,label, select,option,textarea,button,fieldset,legend,table{font-size:18px;FONT-FAMILY:verdana;}
- When you splice the query database language, leave a space after the LIMIT keyword, And the spliced content must be wrapped in an arc.
$sql= "SELECT * FROM pages LIMIT ".(($page-1)*5).",5";
- When displaying pages, the author's logic is complex and can be simplified.
// 1, mainly $ total_pages> $ show_page. In special cases, consider it. // 2. Use the for loop to display all; // 3, consider the ellipsis if ($ total_pages> $ show_page) {// consider the normal situation ,... 456... if ($ page-$ page_off> 1) $ page_banner. = "... "; $ start = $ page-$ page_off; // in abnormal conditions, 12... next page end page if ($ start = 0) $ start = 1; $ end = $ page + $ page_off ;//... 78 total 8 pages if ($ end> $ total_pages) $ end = $ total_pages; for ($ I = $ start; $ I <= $ end; $ I ++) {// the current page is highlighted if ($ page = $ I) {$ page_banner. = "<span class = 'curr Ent '> $ I </span> ";} else {$ page_banner. =" <a href =' ". $ _ SERVER ['php _ SELF ']."? P = ". $ I. "'>{$ I} </a>" ;}} if ($ page + $ page_off <$ total_pages) $ page_banner. = "... "; // display the last page and next page if ($ page <$ total_pages) {$ page_banner. = "<a href = '". $ _ SERVER ['php _ SELF ']. "? P = ". ($ page + 1 ). "'> next page> </a>"; $ page_banner. = "<a href = '". $ _ SERVER ['php _ SELF ']. "? P = ". ($ total_pages ). "'> last page </a>";} else {$ page_banner. = "<span class = 'disable'> next page> </span>"; $ page_banner. = "<span class = 'disable'> last page </span> ";}}
Final Effect
The above is a detailed explanation of how to implement paging navigation for PHP and MYSQL. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!