nishmgopal Posted April 2, 2009 Share Posted April 2, 2009 Hi guys, I want to insert a new record into a table, but the data is going into different tables, is this possible? basically, I have a job table and this has Job Name and Job ID, then i have Skill Table, this is skill name and skill id and finally a table which brings these together, Main Table, this has the job ID, Skill ID and a particular weight for each skill. The Job ID and SKill ID are automatically created. what would my sql query look like if i wanted to insert: a job name with skill 1, skill 2 and skill 3 and skill 1 weight=2, skill 2 weight=3 and skill 3 weight=4 Job name would go into Job table, Skill 1, 2 and 3 would go into skill table and then the Job ID, Skill ID and Weight would go into Main table. My first thoughts are that i need more than one query Quote Link to comment https://forums.phpfreaks.com/topic/152296-insert-intohelp-please/ Share on other sites More sharing options...
Maq Posted April 2, 2009 Share Posted April 2, 2009 Yes it's possible but you're going to need 2 separate queries for this. And what exactly is your question? You can use mysql_insert_id() to get the last inserted id. Quote Link to comment https://forums.phpfreaks.com/topic/152296-insert-intohelp-please/#findComment-799777 Share on other sites More sharing options...
nishmgopal Posted April 2, 2009 Author Share Posted April 2, 2009 sorry, i guess it wasnt much of a question, more asking for an opinion... I wasnt aware of the mysql_insert_id function, so i can use this to get the last inserted ID and then insert this id into a different table? Quote Link to comment https://forums.phpfreaks.com/topic/152296-insert-intohelp-please/#findComment-799783 Share on other sites More sharing options...
Maq Posted April 2, 2009 Share Posted April 2, 2009 I wasnt aware of the mysql_insert_id function, so i can use this to get the last inserted ID and then insert this id into a different table? Sure. For example: If you enter a Job ID into your JOB table then you can get that unique auto-incremented id with mysql_insert_id so when you go to insert into the SKILL table you can match that Job id. Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/152296-insert-intohelp-please/#findComment-799786 Share on other sites More sharing options...
nishmgopal Posted April 2, 2009 Author Share Posted April 2, 2009 thank you for that, i will try coding the page tomorrow and report back...thank you once again Quote Link to comment https://forums.phpfreaks.com/topic/152296-insert-intohelp-please/#findComment-799792 Share on other sites More sharing options...
Maq Posted April 2, 2009 Share Posted April 2, 2009 thank you for that, i will try coding the page tomorrow and report back...thank you once again Roger that. Quote Link to comment https://forums.phpfreaks.com/topic/152296-insert-intohelp-please/#findComment-799795 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.