Efficient Previous/Next item query from database
Posted: Wed Jun 22, 2011 7:01 pm
I'm working on a build log which has many log entries in a database.
If I am browsing log entry 8, then obviously the next will be 9 and the previous will be 7.... How do you query a database for record 8 plus an offset to either side?
This is for finding the entry identifier for a "next" and "previous" button, so you can step through the build log, entry by entry.
I could drop all of the records into an array, search for the one I want and then pull the next/previous based on the array key, but this is a common enough task, is there an better way to return this in a SQL statement?
If I am browsing log entry 8, then obviously the next will be 9 and the previous will be 7.... How do you query a database for record 8 plus an offset to either side?
This is for finding the entry identifier for a "next" and "previous" button, so you can step through the build log, entry by entry.
I could drop all of the records into an array, search for the one I want and then pull the next/previous based on the array key, but this is a common enough task, is there an better way to return this in a SQL statement?