Jump to content

MySQL Query Help


RavenStar

Recommended Posts

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 :P

 

Thanks in advanced~

Link to comment
https://forums.phpfreaks.com/topic/174940-mysql-query-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.