in reply to Re^2: Calculating previous/next from database
in thread Calculating previous/next from database

Meh. If your requirement is a single query, then you need to implement a linked list in the database. This isn't that hard, but it requires that all inserts and deletes update 3 rows vs. just selects doing three queries. This probably is ok.
CREATE TABLE images ( id INT ,prev_id INT ,next_id INT ,other_columns_here );
Then, to get everything in a single query, you do:
SELECT * FROM images WHERE ( (id=?) OR (next_id=?) OR (prev_id=?) );
Not that hard. :-)

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?