0
我試圖TI插入JSON數組我的MySQL database.Here我給格式爲插入嵌套的JSON數組到數據庫
array ${
"customer_id": "1",
"products":[ {
"product_id": "1",
"product_qty": "2"
}, {
"product_id": "2",
"product_qty": "4"
}, {
"product_id": "3",
"product_qty": "12"
}, {
"product_id": "4",
"product_qty": "22"
}],
"order_totalamount": "100"
}
我試過如下插入查詢:
foreach($data as $item) {
//insert into mysql table
$sql = "insert into `order`(cm_id,product_id,product_quantity,order_totalamount,order_id,order_date) values ($cus_id,$item[product_id],$item[product_qty],$order_totalamount,$cus_id,CURDATE())";
也解碼JSON數據和foreach循環
什麼,當你嘗試會發生什麼?你是否收到錯誤信息?這是怎麼說的?你能詳細說明*還解碼JSON數據,並foreach循環*? –