I am making an e-commerce website. Where I have to show the total amount of all the product which is in the cart. But when I try to get the total amount of all product so it only shows the price of the last product Here is the code
$result = $query->fetchAll(PDO::FETCH_ASSOC);
$total = 0;
if($result > 0){
foreach($result as $row){
$price = $row['price'];
$total += intval($price);
}
Because the price was in varchar in the database so I converted into an int using intval() method and echo $total
<td class="pro-subtotal"><span><?php echo $total; ?></span></td>
But its showing amount of the last row in the list