rvdb86 Posted October 6, 2009 Share Posted October 6, 2009 Hi hope someone can give me any suggestions, I am creating a system where I have apartments and each apartment has a type. The apartments are stored in a table called apartments and the different types are stored in a table called types. to link the apartments to their type i have a third table called typeLink which has the following fields: id apartmentID typeID the problem i have is that when i insert a new apartment into the apartment table i want to create the link at the same time. However, the apartmentID is created automatically when a new record is inserted, so how can I get the apartmentID straight after the insert query to insert it into the typeLink table. I hope i have explained myself clearly. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/176695-solved-what-is-the-best-way-to-insert-into-multiple-tables/ Share on other sites More sharing options...
Mchl Posted October 6, 2009 Share Posted October 6, 2009 Assuming it's MySQL you're using, it's mysql_insert_id you're looking for (or it's mysqli counterpart). Link to comment https://forums.phpfreaks.com/topic/176695-solved-what-is-the-best-way-to-insert-into-multiple-tables/#findComment-931551 Share on other sites More sharing options...
rvdb86 Posted October 6, 2009 Author Share Posted October 6, 2009 Hey Mchl, thanks for the quick reply! Looks like that is exactly what i needed. I am going to try it and let you know how it goes Link to comment https://forums.phpfreaks.com/topic/176695-solved-what-is-the-best-way-to-insert-into-multiple-tables/#findComment-931554 Share on other sites More sharing options...
rvdb86 Posted October 6, 2009 Author Share Posted October 6, 2009 works like a charm! thanks alot Link to comment https://forums.phpfreaks.com/topic/176695-solved-what-is-the-best-way-to-insert-into-multiple-tables/#findComment-931684 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.