Moving rows between tables
| From: | Gerald Kaszuba | Date: | Mon, 20 Nov 2000 03:00:54 +0000 |
| Subject: | Moving rows between tables | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-26183@lists.php.net to get a copy of this message | ||
Hi there..
This block of code copies rows from one table to another. Is there a better
way to do this? Maybe via SQL?
$q = "SELECT * FROM table1 WHERE group = $grp";
$r = mysql_query($q);
while ($d = mysql_fetch_array($r)) {
$q = "
INSERT INTO table2
(group, field1, field2, field3)
VALUES
($grp, $d[0], $d[1], d[2])
";
mysql_query($q);
}
Thanks
Gerald