NYCPHP Meetup

NYPHP.org

[nycphp-talk] Paging Strategies

Dell Sala dell at sala.ca
Thu Oct 18 15:05:56 EDT 2007


Every time I implement paging for search results I end up using  
different approaches, but I'm never happy with any of them. Am I  
missing a simpler, more "correct" solution here? Here's what I've tried:


1) TWO-QUERY APPROACH

on every page view:

- step 1: execute search query with a "SELECT count(*) " to get the  
total record count

- step 2: run the search again with the appropriate LIMIT clause to  
retrieve the records I need for the current page



2) ONE QUERY, SEEK TO RESULTS

on every page view:

- step 1: execute search query

- step 2: use *_data_seek() to move to the right slice of results for  
the current page



3) ONE QUERY, CACHE EVERYTHING

on the first page view:

- execute search query, fetch all results, and cache them

on every other page view:

- retrieve the right slice of results from the cache




-- Dell





More information about the talk mailing list