//get next
"Select id from gallery_image where id > '$image_id' and album_id = '$album_id' and profile_id = '$profile_id' order by date asc Limit 1"
//get previous
"Select id from gallery_image where id < '$image_id' and album_id = '$album_id' and profile_id = '$profile_id' order by date desc Limit 1"
I'm no expert, but this one of the best way that i can think of, if anyone of your here knows a better method, please share with us, i am interested too.