0

I am doing sum with the below query but it is not giving result properly.

If there are four items and it is showing the result like: 1.000 2.000 3.000 4.000 and it should be like 10.000

![enter image description here

I don't know where I am mistaken please help.

<?php
$order_temp =   mysql_query("select * from temp_cart
where item_id = '".$mitem_idC."'  and ses_mem=113 order by id");

while ($torder = mysql_fetch_array($order_temp)) {
    $prITTC     =   $torder['item_id'];
    $qtyT       =   $torder['qty']; 

    $chTP   =   mysql_query("
    select * from temp_choices
    where item_id = '".$prITTC."'
    AND ses_mem = 113
    AND status = 1
    ");
    while($chGET    =   mysql_fetch_array($chTP)){
    $fID    =   $chGET['id'];
    $field  =   $chGET['choice_id'];

    $order_tempCHP      =   mysql_query("
    select sum(price) as total, id, ename, choice_id, item_id, price
    from choice_price
    WHERE
     id IN('$field')
    ");
    while ($torderCP    = mysql_fetch_assoc($order_tempCHP)){

    $totalCH    =   $torderCP['total'];

    $tsl    = $totalCH+($qtyT*$prIDTC);

$altsl  = number_format($tsl, 3, '.', '');
echo $altsl;
    } }

}
?>

1 Answers1

0

according to my question above after trying and trying i found the solution and resolved my problem according to below code:

Thanks to @John Kugelman at MySQL query using an array

    $order_temp =   mysql_query("select * from temp_cart
    where item_id = '".$mitem_idC."'  and ses_mem=113 order by id");
    while ($torder = mysql_fetch_array($order_temp)) {
        $prITTD     =   $torder['id'];
        $prITTC     =   $torder['item_id'];

$chTPaa =   mysql_query("
select choice_id
FROM temp_choices
WHERE item_id = '$prITTC'
AND ses_mem = 113
AND status = 1
group by choice_id
");
while ($chGETaa =   mysql_fetch_assoc($chTPaa)){
$temp[] = $chGETaa['choice_id'];
}
$thelist    =   implode(",",$temp);

    $order_tempCHP      =   mysql_query("
    select sum(price) as total
    from choice_price
    WHERE
     id IN ($thelist)
    AND
        item_id = '".$prITTC."'
    ");
    while($torderCP     = mysql_fetch_assoc($order_tempCHP)){
    $totalCH    =   $torderCP['total'];

    $tsl    = $totalCH+($qtyT*$prIDTC);

$altsl  = number_format($tsl, 3, '.', '');
echo $altsl;
    } }
Community
  • 1
  • 1