sturgeon Posted November 23, 2008 Share Posted November 23, 2008 Hello All, I am creating a shopping site, I have two tables orders and order_items. I am keeping order date and user id in orders table. In order_items i am keeping order_id, product_id and quantity. The problem i am facing is, when the user puchases products how will i add datas to these tables both. I mean i add order date and user id in orders table but i should add them to order_item table but how will i add the order_id in that table? If you understand and reply to me i am so glad. Thank you very much and have a nice day. Link to comment https://forums.phpfreaks.com/topic/133926-adding-into-multiple-tables/ Share on other sites More sharing options...
Mchl Posted November 23, 2008 Share Posted November 23, 2008 mysql_insert_id will give you last ID inserted with previous query. Link to comment https://forums.phpfreaks.com/topic/133926-adding-into-multiple-tables/#findComment-697135 Share on other sites More sharing options...
sturgeon Posted November 23, 2008 Author Share Posted November 23, 2008 Thank you, Ok but what will happen when another user purchases something and added to orders ? the id's will differentiate ? Link to comment https://forums.phpfreaks.com/topic/133926-adding-into-multiple-tables/#findComment-697138 Share on other sites More sharing options...
Mchl Posted November 23, 2008 Share Posted November 23, 2008 I'm not sure. I'd guess that it will keep the data for current connection (i.e. other users' action should have no effect). However you can always lock both tables for writing before you do inserts (remember to unlock after), or use transactions (InnoDB storage required). Link to comment https://forums.phpfreaks.com/topic/133926-adding-into-multiple-tables/#findComment-697140 Share on other sites More sharing options...
sturgeon Posted November 23, 2008 Author Share Posted November 23, 2008 Thank you for your replies Mchl, I will try that. Link to comment https://forums.phpfreaks.com/topic/133926-adding-into-multiple-tables/#findComment-697143 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.