I'm trying to get total price from cart table. The product_price in other table which is product. I'm only getting the latest price not the total price. Thanks
function total_price () {
$total = 0;
global $db;
$ip = getIp();
$sql = $db->query("SELECT * from cart WHERE ip_add='$ip'");
$row = $query->fetch(PDO::FETCH_ASSOC);
if ($row) {
}
$no=$sql->rowCount(); // number of rows affected by the last SQL statement
if ($no == 0) {
echo "";
} else {
foreach($sql as $row)
$product_id = $row["p_id"];
$sql = $db->query("SELECT product_price from product WHERE product_id='$product_id'");
$no=$sql->rowCount(); // number of rows affected by the last SQL statement
if ($no == 0) {
echo "";
} else {
foreach($sql as $row)
$product_price = array($row["product_price"]);
$values = array_sum($product_price );
$total += $values;
}
}
echo "RM" . $total;
}
}
I'm trying to get total price from cart table. The product_price in other table which is product. I'm only getting the latest price not the total price. Thanks