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?

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?

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.