Re: moving a selection of records from one table to another (identicalin structure) table?
| From: | Kae Verens | Date: | Wed, 27 Sep 2006 12:07:05 +0000 |
| Subject: | Re: moving a selection of records from one table to another (identicalin structure) table? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-42414@lists.php.net to get a copy of this message | ||
Evert wrote:
Hi all! What is the best/easiest way to use PHP to move a selection of MySQL records from one table to another table, which is in the same database and which has the same structure as the first table?here's a stab at it (not tested): $ids_to_get(1,3,5,6,8); $q=mysql_query(
'select * from from_table
where id="'.join('" or id="',$ids_to_get).'"'
);
while($r=mysql_fetch_array($q)){
$fields=array();
foreach($r as $k=>$v)$fields[]=''.$k.'="'.addslashes($v);
echo('insert into to_table set '.join(',',$fields).'<br />');
# mysql_query('insert into to_table set '.join(',',$fields));
}
obviously, first try the above to make sure the SQL looks right, before you uncomment the line that does the damage
Kae