BigChief Posted May 12, 2010 Share Posted May 12, 2010 I'm wondering if anyone can help me with a little problem I have. I have the following tables: users courses skillsets cidsid I have a page which we will call courses for now and this page allows you to add a new course placing the data from that page into the courses table. The courses page pulls data from the skillsets table to allow you to add a course to a specific skillset. Here is my problem: On submit the courses page inserts the data into the courses table but I would like it to take the course id it has just created based on the name given to the new course, take the skillname from the same row, lookup the skillname on the same row but in the skillsets table, take the ID that relates to it in the skillsets table and post both the skillsetid and the new course id into the table cidsid. I know that sounds a wee bit confusing so here is what I thought (but obviously am wrong) the sql should be. $courseid = mysql_query ("SELECT courseid FROM courses WHERE coursename = " . $_POST['cname'] ); $skillid = mysql_query ("SELECT skillid FROM skillsets WHERE skillname = " . $_POST['skillname'] ); mysql_query ("INSERT INTO cidsid (cid, sid) VALUES EQUALS (".$courseid.", ".$skillid.")"); Any help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/201481-some-help-with-relational-db-query/ Share on other sites More sharing options...
BigChief Posted May 12, 2010 Author Share Posted May 12, 2010 I finally got it: $query = "SELECT courseid FROM courses WHERE coursename = '" . $_POST['cname'] ."'" ; $result = mysql_query ($query); $row = mysql_fetch_array($result); $courseid = $row['courseid']; $query = "SELECT skillid FROM skillsets WHERE skillname = '" . $_POST['skillname'] ."'"; $result = mysql_query ($query); $row = mysql_fetch_array($result); $skillid = $row['skillid']; $query = "INSERT INTO cidsid (cid, sid) VALUES (".$courseid.", ".$skillid.")"; $success = mysql_query ($query); Quote Link to comment https://forums.phpfreaks.com/topic/201481-some-help-with-relational-db-query/#findComment-1057105 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.