I am trying to make a photo gallery in php + mysql.
The URL viewphoto.php?id=143 shows photo 143.
In the navigation menu, I want to display the previous two photos in that album, and the next two.
I thought of using:
$temp_id = $id - 2;
mysql_query("SELECT id, photo FROM photos WHERE album = {$album} AND id >= {$temp_id} LIMIT 5");
But that didn’t work, because photo’s from different albums could have the ids preceding and succeeding the one of the viewed photo.
Does anyone know how I could do this?
Thanks.
I’ve been dealing with this issue myself and I never found an elegant solution to the problem, I ended up doing it in two queries:
Now the first item in “prev” once fetched would be the current photo.
This solution does has to be amended with a check that the first item in “prev” is in fact the requested id, because it doesn’t make sure it’s the proper id, in case of gaps in the series.