这是接收到php脚本的示例数据
[{"id":1,"due_date":"2011-09-03","due_amount":"48279.00","wo_interest":"45980.00"},
{"id":2,"due_date":"2011-10-03","due_amount":"48279.00","wo_interest":"45980.00"}]
并且表格字段按此顺序
loan_no,i_id,due_date,installment,due_amount,wo_interest
低于与接收的json数据匹配的顺序。
i_id,due_date,due_amount,wo_interest
如何向此添加loan_no和installment并使用它进行mysql查询?
答案 0 :(得分:1)
$array = json_decode( $sample_data_recieving );
foreach ( $array as $row ){
$row['loan_no'] = 'SOMETHING_YOU_WANT';
$row['installment'] = 'SOMETHING_YOU_WANT';
mysql_query("
INSERT INTO tbl (i_id,due_date,due_amount,wo_interest,loan_no,installment)
VALUES ('" . implode( "','", $row ) . "')" );
}
答案 1 :(得分:0)
你必须
$arr = json_decode($json,true);
循环遍历它,写下你的查询,在这种情况下顺序无关紧要
答案 2 :(得分:0)
您可以通过以下步骤完成此操作:
$res = array_merge($json_array, array( 'loan_no' => 12);
订单与MYSQL INSERT无关。