I need to create previous / next functionality with cycling. My current solution, If I select MAX(ID)
gives next as NULL
.
How can I most e
for next and previous id for the current foto
you can do like this
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`
Hope it works fine for your needs