How To Find The ID Of A New Row With MySQL
Computing : Learning PHP Often when you insert a new row into a database you will want to know the ID of that new row straight away. For instance you might be using that ID to enter some more information into a separate table and that ID is the join. Thus if you have a users table and an optional information table you might want the new row ID from the users table to then use to insert more info about that member in option information table. As ever mySQL can help you out and tell you this id, yet many people issue an unneccesary query after the insert, e.g. SELECT id FROM users ORDER BY id DESC LIMIT 1 which they then use to insert the data in the second. However you can get the info of the id of the new row simply by this: $newid = mysql_insert_id(); and that's all there is to it!
Questions about PHP and mySQL:
|
|