2016-07-18 6 views
0

以下のクエリで合計を計算していますが、結果が適切に与えられていません。php mysqlクエリが適切に合計を実行していません

そこに4つの項目があり、それは次のように結果が表示されている場合: 1.000 2.000 3.000 4.000、それは私が間違っていますどこ私は知らない10.000

![enter image description here

ようにする必要があります助けてください。しようと、私は解決策を見つけたし、コードの下に応じて私の問題を解決しようとした後、上記の私の質問に応じ

<?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; 
    } } 

} 
?> 
+0

であなたが示したことができますデータと期待される結果は?また、PHPを使わないクエリだけでいいです。 – Philipp

+0

私は10秒間しか読んでいません。 dbエンジンがあなたのために仕事をするようにしてください。ループを使ってPHPエンジンをdbエンジンの一部にしています。 (Read:100 times slower) – Drew

+0

@Philipp私が画像を追加したことを確認してください。 –

答えて

0

:@ジョンKugelmanへ

おかげ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; 
    } } 
関連する問題