Hi,
I'm trying to rip one line out of a table and stick it directly into a duplicate table. i.e. identicle structure but different table name.
Something like this:
$insertDupe = "INSERT INTO sdSeedOriginal SELECT * FROM sdSeed WHERE ideaId=".$HTTP_POST_VARS['ideaId'];
Is that a good way to do it... I'm currently backing up a very large DB before I try. 🙂
// configure these variables please $oldtable = 'table'; $newtable = 'table_copy'; $query = mysql_query("SELECT * FROM $oldtable"); while ($query = mysql_fetch_array($query)) { mysql_query("INSERT INTO $newtable VALUES ($query[col1], $query[col2], $query[col3])"; }
Replace the values with your own. Enjoy! (Let me know if you require further assistance 😉)
Also, what this does is copies the rows from a table first (all of them), THEN insert each one at a time into a new table.
Yes,
Your approach is correct.
If both tables are identical,
INSERT INTO table1 SELECT * FROM table2 WHERE ...
If the tables are not identical, then
INSERT INTO table1 (var1,var2,var3) SELECT var1,var2,var3 FROM table2 WHERE ...
Richie.