我想用二维数组更新表。 数组如下所示:
0:
longdescription: ""
order_nr: "1"
parts_id: "7478"
pos_description: "Zylinderkopfdichtung "
pos_discount: 0
pos_emp: "0"
pos_id: "115486"
pos_instruction: false
pos_price: "062.18"
pos_qty: "01.00"
pos_status: "gelesen"
pos_total: "62.18"
pos_unit: "Stck"
1: {order_nr: "2", , …}
2: {order_nr: "3", , …}
3: {order_nr: "4", , …}
这是当前代码:
$GLOBALS['dbh']->begin();
foreach( $data as $key => $value ){
$GLOBALS['dbh']->update( $value['pos_instruction'] == 'true' ? 'instructions' : 'orderitems', array( 'position', 'parts_id', 'description', 'unit', 'qty', 'sellprice', 'discount', 'marge_total', 'u_id', 'status', 'longdescription'), array($value['order_nr'], $value['parts_id'], $value['pos_description'], $value['pos_unit'], $value['pos_qty'], $value['pos_price'], $value['pos_discount'], $value['pos_total'], $value['pos_emp'], $value['pos_status'], $value['longdescription']), 'id = '.$value['pos_id'] );
}
echo $GLOBALS['dbh']->commit();
由于该数组在第一维中有20-50个对象,因此foreach循环会花费很长时间。 因此,我正在寻找一种方法,可以从整个数组中一次更新表[指令和订单项],而不将其拆分为一维。
欢呼