Reputation: 1750
I want to paginate some result using
LIMIT no_of_rows, row_offset
query in mysql
I runt a script that does this via ajax, the problem is when I fetch the last rows. How can I fetch the last rows via mysql limit without getting any errors?
Upvotes: 0
Views: 99
Reputation: 53606
The first time you query the table (assuming it does not change every second) Do it like that:
SELECT SQL_CALC_FOUND_ROWS *
FROM table_name LIMIT page_size,0;
SELECT FOUND_ROWS();
That way you know how many rows to expect, and you do not give a LIMIT
which does not exists.
Upvotes: 1