PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm creating a gallery of pictures. The picture id are not in any order.
What i would like to do is to do a query on the db and that brings back 3 id's, pic1 and pic2. your GID will be set in the URL ex. http://test.com?gid=10
I need to display the one that matches the gid the one before and the one after.
This is the code that i have been using but's isn't working.
$sql = "SELECT id, picture FROM gallery WHERE id = ".$gid." or id = ".($gid + 1)." or id = ".($gid - 1)."
This returns three pictures , one before and one after gid, also this doesn't create error if there is no picture with that id. (My code is not good since it assumes that there are no "holes" in id number chain...)
One possibility is to get all id's from gallery, and find the closest next and previous id's using array functions and (sql)sorting. And then get the three pictures.