for næste og forrige id for det aktuelle foto
du kan gøre sådan her
SELECT COALESCE((SELECT id FROM `foto` WHERE id<'$this->id' ORDER BY DESC id LIMIT 1),
(SELECT MAX(id) FROM `foto`)) AS `prev`,
COALESCE((SELECT id FROM `foto` WHERE id>'$this->id' ORDER BY id LIMIT 1 ),
(SELECT MIN(id) FROM `foto`)) AS `next`
Håber det fungerer fint til dine behov