Forum Moderators: coopster

Message Too Old, No Replies

How can I catch Next and Previous Id in mysql?

         

setareh

6:29 pm on Jun 20, 2005 (gmt 0)

10+ Year Member



I have a table, named T1,
in this table some records added and some records are deleted, and ids for this table are not consecutive,
(e.g id=1,2,5,6,8,...)
I call a record with this query:
$result=mysql_query("SELECT * FROM `T1` WHERE `id`='$id", $connect);
$records=mysql_fetch_row($result);

How can I catch next or previous record of certain id?

lobo235

6:47 pm on Jun 20, 2005 (gmt 0)

10+ Year Member



You would do two SELECT statements like this:

SELECT id FROM table_name WHERE id < 14 ORDER BY id DESC LIMIT 1;

and

SELECT id FROM table_name WHERE id > 14 ORDER BY id LIMIT 1;

setareh

7:39 pm on Jun 20, 2005 (gmt 0)

10+ Year Member



thanks lobo ;)