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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.