Fmdpa Posted August 21, 2010 Share Posted August 21, 2010 I'm creating a photo page, and there are navigation arrows on it. What I did (for the "previous photo" button) was to select the last ID (current id - 1) and fetch the url associated with that row. The query looked like this: SELECT imageurl FROM images WHERE id="$currentID - 1" It works flawlessly UNLESS the previous photo had been deleted. Then the id I have in the query refers to a non-existent row, which returns a bunch of errors. Is there a way I can easily select the previous id whether it is exactly "id - 1"? Link to comment Share on other sites More sharing options...
Fmdpa Posted August 21, 2010 Author Share Posted August 21, 2010 Aha! SELECT imageurl FROM images WHERE id < $currentID ORDER BY id DESC LIMIT 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.