Re: Moving rows between tables
| From: | David Robley | Date: | Mon, 20 Nov 2000 03:35:45 +0000 |
| Subject: | Re: Moving rows between tables | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-26189@lists.php.net to get a copy of this message | ||
On Mon, 20 Nov 2000, 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);
> }
>
> Thanks
> Gerald
SELECT .... INTO TABLE jumped to mind, but it appears this syntax isn't
supported by mySQL - use INSERT ... SELECT instead.
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA