MySQL uses the cursor paging mode. The next page is well implemented. How does the previous page be implemented?

Source: Internet
Author: User
For mysql to achieve optimal query performance, I changed the paging query method to cursor: {code ...} the above last_id is the last reply reply_id on this page, so that the "next page" can be queried, but how can the "Previous Page" be implemented? I thought about changing the sorting order {code...}... To make mysql achieve the best query performance, I changed the paging query to the cursor query method:

select * from reply where reply_id > last_id limit 20 order by reply_id ASC;

The above last_id is the last reply reply_id on this page, so that the "next page" can be queried, but how can the "Previous Page" be implemented?
I thought about changing the arrangement order.

select * from reply where reply_id < first_id limit 20 order by reply_id DESC;

In this way, we also need to add a parameter to the url. I want to keep the url route as ingress. I have thought about using javascript's history. back (), but it still feels unreliable. is there a better implementation method?

Reply content:

For mysql to achieve optimal query performance, I changed the paging query method to cursor query:

select * from reply where reply_id > last_id limit 20 order by reply_id ASC;

The above last_id is the last reply reply_id on this page, so that the "next page" can be queried, but how can the "Previous Page" be implemented?
I thought about changing the arrangement order.

select * from reply where reply_id < first_id limit 20 order by reply_id DESC;

In this way, we also need to add a parameter to the url. I want to keep the url route as ingress. I have thought about using javascript's history. back (), but it still feels unreliable. is there a better implementation method?

In fact, this is a routing problem, not a MySQL query problem...

There are many methods... For example

  1. Last_id distinguishes between positive and negative numbers
    Www.example.com/reply/12345stands for the next page
    Www.example.com/reply/-12345represents the previous page.

  2. Redefine routing rules
    Www.example.com/reply/next/12345 next page
    Www.example.com/reply/previus/12345 Previous Page

Cursor is suitable for unlimited loading. We recommend that you use the traditional method for paging.

PS: the traditional method is still converted to cursor... Therefore, your statement "to achieve optimal query performance" is not accurate.

If you want to solve the problem simply, add twoIn this way, the next page on the PC side and more loading on the Mobile side can be implemented.

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.