RE: [PHP] Moving rows between tables

From: Date: Mon, 20 Nov 2000 04:14:00 +0000
Subject: RE: [PHP] Moving rows between tables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-26193@lists.php.net to get a copy of this message
On 20-Nov-00 Gerald Kaszuba wrote: > 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); > } > $qry="insert into tbl2 (group, f1, f2, f3) select $grp, * from tbl1 where group = '$grp'"; Regards, -- Don Read dread@texas.net -- The problem with people who have no vices is that you can be sure they're going to have some pretty annoying virtues.

« previous php.general (#26193) next »