Jump to content

Inserting data from one table into another with different values?


Elven6

Recommended Posts

I want to take data from one table and insert it into another in the same database, the problem is the two tables have different values so it wouldn't be as simple as using an INSERT INTO script.

 

From table 1 I want to extract a row ID as well as a field called systems. I then want to insert that into the second table which is structured,

 

Id (null)

Name (games)

Value (the data given from Systems in the other)

ID2 (the ID from the other table)

Category (news)

 

Any ideas how I can go about this?

Link to comment
Share on other sites

something like this?

$query = mysql_query("SELECT id,systems FROM table1");
while($row = mysql_fetch_array($query)) {

   mysql_query("INSET INTO table2  (`id2`, `value` ) VALUES ({$row['id']}, {$row['systems']})");
}

 

Thanks for the code, I'll see if it works. One question though, what are the {} around things like $row['id'] for?

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.