Just started using PHP and mySQL to create a web site and I had a quick question:
When pulling back info from MySQL and you know you are going to get just one item back is there an easy way to get this variable? I am adding a new item to my database and need to get back the ID that is auto_incremented in order to add the rest of the info to other tables. I want to use MAX (unless there is a better way), but I couldn't figure it out so this is the code that I am using, but I don't feel confortable with it:
$q = "SELECT List_ID from User_Master_Lists";
$result = mysql_query($q);
while ($MaxListID = mysql_fetch_assoc($result))
{
$ListID = $MaxListID[List_ID];
}
From what I think is going on, this query is going through 'every' item in the database and this seems silly. If I could use 'SELECT MAX(List_ID) from User_Master_Lists' to get the info I think this would be better. I am going to be using MySQL to get back single rows a lot and I would like to get this cleared up before I procede.