我想知道,如何将一列数据从一个表数据复制到mysql中的另一个表,并同时插入更多值。
表1:
**id:** 1
**Items :** [{"id":"9","size":"64 GB","quantity":"1"},{"id":"9","size":"32 GB","quantity":2},{"id":"1","size":"32","quantity":"1"},{"id":"5","size":"8","quantity":"1"},{"id":"2","size":"38","quantity":"1"}]
**Create_Date:** 31/08/2018
**Exp_date:** 01/09/2018
表2:
**id:**
**Order_id:**
**Items:**
**Paid:**
我想复制表1的项目并将其插入表2,同时我要插入在表2中支付的order_id
为此,我正在尝试:
$order_id = "DJ9JQY4J00248";
$paid = "Order Complete";
$insertSql = "INSERT INTO table2 (`order_id`,`paid`) VALUES ('$order_id','$paid') AND (items) SELECT items FROM cart WHERE id = '{$cart_id}'";
$db->query($insertSql);
请提出我在做什么错。上面的代码对我不起作用。
答案 0 :(得分:0)
您可以移动变量以选择
INSERT INTO table2
(`order_id`,`paid`, items)
SELECT '$order_id','$paid', items FROM cart WHERE id = '{$cart_id}'