How does php and mysql paging particularly large data volumes?

Source: Internet
Author: User
How does php paging particularly large data volumes?

Reply content:

How does php paging particularly large data volumes?

The paging method is as follows:

SELECT * FROM posts order by id desc limit $ page_size OFFSET $ offset

However, when $ offset is large, the speed will be slow.

In this case, you can use "Previous Page" and "next page" for paging, for example:
60-41 (Previous Page) 40-21 (current page) 20-01 (next page)
Next page (20 old articles ):

// Page. php? Id =-21 negative number indicates the next page old article here 21 indicates the ID of the bottom article on the current page. SELECT * FROM posts WHERE id <21 order by id desc limit 20;

Previous Page (20 new articles ):

// Page. php? Id = 40 positive number indicates the ID of the top article on the current page in the new article on the previous page. SELECT * FROM posts WHERE id> 40 order by id asc limit 20;

The obtained result is the ascending ID sequence. PHP uses the array_reverse reverse array to implement the descending output.

If negative numbers are not good, you can add an additional parameter, for example:
Page. php? Action = next & id = 21
Page. php? Action = prev & id = 40

The above describes a solution. I will talk about a latency association query.

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.