Detailed paging navigation ideas for PHP and MYSQL implementation and detailed paging ideas for mysql

Source: Internet
Author: User
Tags php and mysql

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!

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.