MySQL Forums
Forum List  »  Newbie

unique ID field, getting next and previous existing ID from table
Posted by: Rikado Malani
Date: February 10, 2007 10:40AM

Hi everyone,

This has been haunting me. In a query I select an ID (the ID field in the table is set to unique) The variable to check against ID is created by user in a form. To prevent unneccesary queries, I'd also like to know what the *next* and the *previous* ID will be.

This is the first query

$results = mysql_query("SELECT * FROM $mytable WHERE ID='$id'");

And now I want to find out what the next ID and previous ID will be from that table. The user can delete records from table, so I can't assume that if user wants a result where ID=8, that records with ID=7 and ID=9 exist.

I hope I explained myself clearly :)

Options: ReplyQuote


Subject
Written By
Posted
unique ID field, getting next and previous existing ID from table
February 10, 2007 10:40AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.