in reply to Calculating previous/next from database
Sounds like you want a Database Cursor. Some DB software makes this easy and some require something manual. What DB engine do you have?