RavenStar Posted September 20, 2009 Share Posted September 20, 2009 Hi all~ I'm in the processing of constructing my own forum software in PHP but have hit a slight road bump with a sql query. I'm trying to come up with the most optimal way. Here is what I'm trying to do, The sql query needs to insert into 2 different tables, not the same data ofcourse. $w = numeric value "INSERT INTO threads ('parent', 'subject'.....etc) VALUES ('". $w ."', '" . $subject . "')"; $a = SHOULD equal the "id" column of the row we just inserted into threads(above). "INSERT INTO posts ('parent', 'name'.....etc) VALUES ('" . $a ."', '" . $name ."')"; So my question is, how would I go about getting $a? I know I could run the first query (insert into threads) then run a select query to find the id of the row we just inserted, and use that id to run the second query(insert into posts), however I'm wondering if there's a better/easier way? Sorry if this is a little confusing to read, I'm not sure how to explain it any easier Thanks in advanced~ Link to comment https://forums.phpfreaks.com/topic/174940-mysql-query-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 20, 2009 Share Posted September 20, 2009 http://us2.php.net/manual/en/function.mysql-insert-id.php Link to comment https://forums.phpfreaks.com/topic/174940-mysql-query-help/#findComment-921956 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.