Pagination Best Practices
Posted: Fri Jan 16, 2009 3:29 pm
I'm not that deep into the internals of MySQL... so please excuse my ignorance when it comes to efficiency.
Let's say I have a (MySQL) database of several thousand records that is updated/added to quite frequently . I want to show, 'pagerows' records at a time with several SQL WHERE conditions. The WHERE conditions may return 0 to all records, depending on the critera.
All I really need are a the pagerows rows of data, and links for Previous, Page-x-of-y , and Next
Which might be the more efficient:
1) Run a SELECT COUNT(*) to get total # of matching records, then run the real SELECT query with the fields and data I want with a LIMIT clause (LIMIT start,pagerows)
2) Run the SELECT query with the fields and data I want using the and perform a while loop : While ($row=$result->FetchRow() {...}) fetching the start through start+pagerows.
3) Your suggestions
Thanks
Let's say I have a (MySQL) database of several thousand records that is updated/added to quite frequently . I want to show, 'pagerows' records at a time with several SQL WHERE conditions. The WHERE conditions may return 0 to all records, depending on the critera.
All I really need are a the pagerows rows of data, and links for Previous, Page-x-of-y , and Next
Which might be the more efficient:
1) Run a SELECT COUNT(*) to get total # of matching records, then run the real SELECT query with the fields and data I want with a LIMIT clause (LIMIT start,pagerows)
2) Run the SELECT query with the fields and data I want using the and perform a while loop : While ($row=$result->FetchRow() {...}) fetching the start through start+pagerows.
3) Your suggestions
Thanks