You WANT to use auto_incremment! That's the only proper way to handle table information. As for the previous and the next row, that's fairly easy. You should query the entire table and have the rows sorted by the auto_incremment column, that would give you a result that contains rows. Every result row would represent a table row and they would be order as created. So there would be no problem with missing index values. You would simply take the previous or the next row from results according to the the row in results that you have the relevant data. Good luck! Airnine
Originally posted by fyrestrtr It will not if the query is encapsulated in ' ', in which case, it will throw a invalid query/syntax error. Which you can catch with mysql_error();
Hmm.. if you are saying that a MYSQL query coded in php, where the WHOLE query is single quoted.. E.G.:
$id = "MyName";
$sql='SELECT * FROM table WHERE id = '$id'';
//Echo will display:
//SELECT * FROM table where id = $id
then yes, the query will always error, since the whole query is seen as a STRING, single quoted strings are taken literally, double quoted strings are parsed, (meaning that single quoted STRINGS will not be parsed, hence, neither will the variables)
THEREFORE, the following IDENTICAL query (double quoted) WILL work.
$sql="SELECT * FROM table WHERE id = '$id' ";
//this will display :
// SELECT * FROM table WHERE id = MyName
(the query string IS parsed, so single quoted within double quotes follows sql syntax perfectly.. )
It's just that the original SQL query posted just before your comment of "if single quoted it will not work" was "probably" intended to be parsed by php..
Just wanted to clear up that point, before some noobs come by and give up in frustration when their code won't work..