Skip to content Skip to sidebar Skip to footer

Pagination Keeps Showing The Same Portion Of Sql Data

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 and it does give me paginat

Solution 1:

Try:

$sql='SELECT * FROM ETF LIMIT ' . $results_per_page . ' OFFSET ' . $this_page_first_result;

Also as mentioned you should sort by a certain column with 'ORDER BY' for consistent results.

Solution 2:

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 .

Post a Comment for "Pagination Keeps Showing The Same Portion Of Sql Data"