Following a conversation at work about methods of pagination and only getting the data you need for a particular page. Is it better to use PHP mysql_data_seek()
on a returned dataset and use code to limit or use SQL LIMIT
to limit results for pagination?
For example we have a built-in function for paginating results but we have to make two queries to use it. First we query the DB to find out how many results are available then we query the db using a LIMIT
keyword to actually get the data for the relevant page.
Would it be better to get the entire dataset and iterate through it using mysql_data_seek()
to get to the relevant page's data before displaying it. This way we can do one query for both needs, i.e to see how much data there is available and then to only get the page we need.
I'm guessing the latter will use more memory and perhaps be slower with bigger DBs?