I have a problem with sum values in while loop. So, I have a database witch has rows with same product name, but different quantities, different ids and different prices. When I do my while loop it prints each product, but I want to print only one and sum quantities.
My result is 11123, not 8, how it should be.
This is my code:
$found = 1;
while($stmt->fetch()){
if(!($data3['Prod_price'] == '0' || $data3['Prod_name'] == ' Acne Cream')) {
$price = $data3['Prod_total'] - ($data3['Prod_total'] *($data3['Discount']/100));
$qty = $data3['Vial_type'] == " 50 Tablete" ? $data3['Prod_qty'] / 2 : $data3['Prod_qty'];
if($data3['Prod_name'] == ' Antioxidant Star'){
if($found==1){ // this is for showing only one product with same name
$found++;
// here should be summed quantity divided by target (to extract the percentage)
$andioxidtrg = $qty / $data2['Trg_antioxidant'];
// here shold be the quantity
$andioxidqty = $qty;
echo 'Antioxidant Star: '.$andioxidqty.' din '.$data2['Trg_antioxidant'].' ('.round( $andioxidtrg * 100 )."%)<br>";
}
}
}
}