When i call this function on my webpage it should echo out the total value of the products in your shopping cart, But it only echo's out the value of the product with highest product id. Instead of the sum of these values combined.
function total_price() {
$total = 0;
global $link;
$ip = getIp();
$sel_price= "select * from cart where ip_add='$ip'";
$run_price= mysqli_query($link, $sel_price);
while($p_price=mysqli_fetch_array($run_price)) {
$pro_id = $p_price['id'];
$pro_price = "select * from products where id='$pro_id'";
$run_pro_price = mysqli_query($link, $pro_price);
while ($pp_price = mysqli_fetch_array($run_pro_price)){
$product_price = array($pp_price['prijs']);
$values = array_sum($product_price);
$total = number_format((float)$values, 2, ',', '');
}
}
echo "€ " .$total;
}
array_sum()on it. So the sum is just the value of that one element. You're not adding to the previous rows.SELECT SUM(prijs) AS totalin the query?