assume that the front end is
<input type="hidden" name="cart_prod_id[]" value="<?=$row["prod_id"];?>">
<input type="hidden" name="cart_quantity[]" value="<?=$row["quan"];?>">
backend
foreach($_POST["cart_prod_id"] as $value){
echo $value;
}
foreach($_POST["cart_quantity"] as $value){
echo $value;
}
you can get a hypothetical value after sending it
11510612910751031
but it is
// ID
115
106
129
107
//
5
10
3
1
I will first find out the merchandise ID, to find his own price
and then come back multiplied by the corresponding quantity
// ID ->
115 -> 5
106 -> 10
129 -> 3
107 -> 1
how can I calculate the price of each item and add it up?
what I do is like this
, but it only counts the last one
$i = 0;
$productTotal = null;
foreach($_POST["cart_prod_id"] as $value){
$product = mysqli_fetch_array($pdo->query(
"SELECT
p.price,
p.original_price
FROM `product` as p
WHERE p.prod_id = "{$value}" "
));
$productTotal += $product["price"] * $_POST["cart_quantity"][$i];
$iPP;
}
echo $productTotal;
the train of thought is dead, please drop it