I have a mysql table where I want to get the inferior (i.e. previous) or superior (i.e. next) item based on the ID of the current selected value.
Like this:
$id_ani = $cap['id_ani']; //Current id
$id_capnex = $cap['id_cap']+1; //Superior id
$nexcap = mysql_query("SELECT * FROM m_table WHERE id_cap=$id_capnex");
$id_caprev = $cap['id_cap']-1; //Inferior id
$prevcap = mysql_query("SELECT * FROM m_table WHERE id_cap=$id_caprev");
So in the code I have the Current id, Superior id, and Inferior id.
The problem here is that if the current id = 1 and the only existing id after 1 is 4 the Superior id would be '1'+1 instead of 4 which is the only existing id after 1. The same applies if I did it with a inferior one.
Is there a way to select 4 instead of 2 and do the same with the inferior id?
Thanks in advance.