简体   繁体   中英

copying multiple records from one table to another (same structure) (PHP/MySQL)

So here is what I am trying to do:

Copy every record from one table where the item_id is that of which is in my array.

mysql_query("INSERT INTO archive_items_tb SELECT * FROM item_bank_tb WHERE item_id IN(" . implode(',', $questions) . ")");

$questions is an array of question ids, parsed to this function.

mysql does not like my attempt, so can somebody please direct to the correct syntax.

thanks

You need to wrap your sub-select in parenthesis. Also, as a note, make sure you escape the values in your $questions array.

<?php
$query = "INSERT INTO archive_items_tb
(
    SELECT * FROM item_bank_tb
    WHERE item_id IN (" . implode(',', $questions) . ")
)";

mysql_query($query);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM