Page 1 of 1

find following row

Posted: Mon Jan 03, 2005 10:48 am
by bytte
I'm using a mysql database.
I display the contents of a row by passing the ID through $_GET

e.g. detail.php?ID=15

now I want a "next" and "previous" button on that page.
What's the query to accomplish this?
Just doing $ID+1 and $ID-1 wouldn't work anymore if I deleted rows in the future...

Any suggestion? I searched through the forums but didn't find a solution. (maybe i searched using the wrong keywords)

Posted: Mon Jan 03, 2005 11:29 am
by feyd
something like

Code: Select all

select * from table_name where id < $id order by id desc limit 1
union select * from table_name where id = $id limit 1
union select * from table_name where id > $id order by id asc limit 1
[mysql_man]union[/mysql_man]