Pagination keeps showing the same portion of SQL data

前端 未结 3 1858
长情又很酷
长情又很酷 2021-01-29 05:46

I have a really large data set from SQL that i need to paginate.

I have an issue with my pagination code. The code does show the page number in the URL

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-29 06:18

    Using OFFSET and LIMIT for pagination of web pages leads to two bugs -- duplicated rows shown, and rows not shown.

    Why?

    1. You are pondering the "first" 10 rows on one web page.
    2. Meanwhile a row is INSERTed or DELETEd that belongs in the first 10.
    3. You click [Next] and go to the page that shows the next 10 rows. But wait, it is not showing the "next" 10 rows, it is showing rows #11-20. And, since something changed in rows 1-10, the rows are not really continuing where you left off.

    I just gave you a hint of how to avoid it -- "remember where you left off" instead of using OFFSET. More .

提交回复
热议问题