MySQL Forums :: Newbie :: unique ID field, getting next and previous existing ID from table


Advanced Search

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 Rikado Malani 02/10/2007 10:40AM
Re: unique ID field, getting next and previous existing ID from table Bob Field 02/10/2007 12:25PM
Re: unique ID field, getting next and previous existing ID from table Rikado Malani 02/11/2007 07:27AM
Re: unique ID field, getting next and previous existing ID from table Evgen Kuligin 02/26/2009 01:52AM
Re: compound ID field, getting next and previous compound ID from table Rick James 02/26/2009 09:58PM


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.