emehrkay Posted September 11, 2006 Share Posted September 11, 2006 where the key that connects them is auto_incriminated and i have no idea what it will be?i have a contact info with a contact_info_id field (this is the main field, but unknown)i want to insert a new contact_info record and update a few other tables at the same time, is that possible? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted September 11, 2006 Share Posted September 11, 2006 When you insert into a table, if there is an auto increment field you can call mysql_insert_id() to get the id of the last value inserted. You can then use that to insert into other tables and link data together.[code]$res = mysql_query("insert some sort of data");$id = mysql_insert_id();if($id){ mysql_query("insert more data using $id to link across tables");}[/code]That's just a quick snippet written from memory. You'll want to check the PHP manual for the specific usages of any functions I've used, in case I misused them.(EDIT) Alternatively you can check the MySQL documentation and see if there is a variation of the INSERT or UPDATE statements that will do this. I don't think they exist though. Quote Link to comment Share on other sites More sharing options...
emehrkay Posted September 12, 2006 Author Share Posted September 12, 2006 thanks, i may have to use that, but i wanted it to be a single query because i have to give a bunch of them to someone and they'll just run them. I dont know which order they'll run them in so...i was thinking that i could do something like UPDATE table1 t1 SET field = value, (INSERT INTO table2 t2 (field) VALUES ('vaue)), field2 = t2.id WHERE t1.id = 'xxx'ill try it tomorrow at work Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.