I’m trying to paginate user submitted information into a catalog. At first I had something like this:
/?page=3&count=20&sort=date
$floor = ($page-1)*$count;
$ceiling = $count;
SELECT * FROM catalog ORDER BY date ASC LIMIT $floor, $ceiling
This, as I have read, is bad since it will count all the results, not stopping at the limit (floor+ceiling).
Now, I’m trying to make it faster by paging with respect to the last item on the page
/?last_date=2012&count=20&sort=date
$ceiling = $count;
SELECT * FROM catalog WHERE date>$last_date ORDER BY date ASC LIMIT $ceiling
However, this won’t work right? Some dates will be the same. For the sake of argument, let’s assume that I cannot use a more precise timestamp. For instance sorting by price would only go to 2 decimal places and there would definitely be overlap.
Is there anything that I can do to make this improvement work, or should i revert back to my previous query?
I ended up using my first pagination example.