I am trying to update multiple rows (MySQL) with data from an array (PHP), but only one row is being updated based on the first values in the array. I know I am just missing a loop somwhere. I am using a foreach loop already but that doesn't seem enough. I am close to getting it. How can I modify my existing code to make sure all rows update with the correct information?
To start, the $unit_details array contains this:
array(3) {
[0]=> array(4) { ["pid"]=> string(5) "29013" ["vid"]=> string(5) "29018" ["tax"]=> string(5) "10.74" ["upr"]=> string(5) "123.6" }
[1]=> array(4) { ["pid"]=> string(5) "29013" ["vid"]=> string(5) "29474" ["tax"]=> string(5) "13.81" ["upr"]=> string(5) "158.9" }
[2]=> array(4) { ["pid"]=> string(5) "29282" ["vid"]=> string(5) "29283" ["tax"]=> string(5) "34.76" ["upr"]=> string(3) "400" }
}
$updtunits = '';
$order_id = '31989';
$upar='';
$uchid='';
$utax='';
$uamt='';
foreach ($unit_details as $udt) {
$upar .= $udt['pid'];
$uchid .= $udt['vid'];
$utax .= $udt['tax'];
$uamt .= $udt['upr'];
$updtunits = $docdb->query(" UPDATE ords_meta
SET net_rev='$uamt',
tx_amount='$utax'
WHERE order_id='$order_id'
AND prod_id='$upar'
AND var_id='$uchid'");
}
Screenshot of database table ords_meta: Link to Database Screenshot Here
source https://stackoverflow.com/questions/68135876/update-multiple-mysql-rows-with-php-foreach-loop-in-array-only-updating-one-ro
Comments
Post a Comment