ckrudelux Posted February 20, 2010 Share Posted February 20, 2010 Need some help with id numbers.Let's say I create a row with some text in it and it gets an id number by auto_increment so I never know what number it gets and I have some options I want to add in an other table. How do I get the id number from the first table so I can add it to my second? Example:Step 1 :Inserting sometext gets id number 66Step 2 :Inserting option: The text should be red where id is 66hope you understand what I'm trying to say. Link to comment Share on other sites More sharing options...
Synook Posted February 20, 2010 Share Posted February 20, 2010 mysql_insert_id() Link to comment Share on other sites More sharing options...
ckrudelux Posted February 20, 2010 Author Share Posted February 20, 2010 mysql_insert_id()If two users post at the same time would this effect the id it gets? Link to comment Share on other sites More sharing options...
boen_robot Posted February 20, 2010 Share Posted February 20, 2010 If two users post at the same time would this effect the id it gets?It shouldn't. This gets the ID of the row you just inserted... at the time of the actual insertion, not at the time of calling the function. If two users post at the same time, MySQL will first solve the conflict, then give each client instance the ID of their row. Your ID may not be the last one if two users have posted at the same time, but it is sure that it will be the one the current instance posted. Link to comment Share on other sites More sharing options...
ckrudelux Posted February 20, 2010 Author Share Posted February 20, 2010 It shouldn't. This gets the ID of the row you just inserted... at the time of the actual insertion, not at the time of calling the function. If two users post at the same time, MySQL will first solve the conflict, then give each client instance the ID of their row. Your ID may not be the last one if two users have posted at the same time, but it is sure that it will be the one the current instance posted.Thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted February 23, 2010 Share Posted February 23, 2010 It handles that by returning the inserted ID for the current connection. As long as the two users are each using a different connection to the database, each will return its own data. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.