Php paging principle tutorial and simple example

Source: Internet
Author: User
The php paging tutorial is as follows: & amp; lt ;? Phpecho & quot; original php Tutorial & quot; // Connect to database $ con = mysql_connect (& quot; localhost & quot;, & quot; root & quot ;, & quot ;);

The php paging tutorial is as follows:


 = $ TotalPageCount )? $ TotalPageCount: $ nowPage + 1; // offset $ offset = ($ nowPage-1) * $ pageSize;/* OK, which gets the data, in fact, as long as you understand the SQL statement, you will understand the paging principle * select * from table limit $ offset, $ size paging execution statement */$ SQL = "select * from stu_msg limit $ offset, $ pageSize "; $ result = mysql_query ($ SQL, $ con); while ($ arr = mysql_fetch_array ($ result) {echo $ arr ['mid ']. $ arr ['content']."
";}Echo" homepage "; echo" previous page "; echo" next page "; echo" last page ";?>

The above php instance runs as follows:

The above php code has been commented out clearly. I believe you will understand it! The following is a simple analysis of the php Tutorial:

1. the global variable $ _ SERVER ['php _ SELF '] is the absolute path for getting the script variable. you can print it out and check it out.

2. the essence of paging is to display data in a database segment, for example, in the above php instance:

Extract the first five (first page): select * from table limit

Retrieve 5th to 10th entries (second page): select * from table limit 5, 5

This gives the formula for offset: $ offset = ($ nowPage-1) * $ pageSize;

3. the intval () function is used to obtain the integer value of the variable.

~ Is php paging so easy !~

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.