luca.p.alexandru
luca.p.alexandru

Reputation: 1750

Paginating result with mysql limit

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

Answers (1)

Itay Moav -Malimovka
Itay Moav -Malimovka

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

Related Questions