php mysql toplam göstermeye çalışıyor

2 Cevap php

Ben int ile qunt almak ve hepsini toplayın ve toplam göstermeye çalışıyorum

$qunt = 0;
$result = mysql_query("SELECT * 
                         FROM properties_items 
                        WHERE user_propid='$view' 
                     ORDER BY id DESC") or die (mysql_error()); 

while ($row = mysql_fetch_array($result)) { 
  $itemid = $row['itemid'];
  $qunt = $row['qunt'];

  $qunt++;
}

echo $qunt;

2 Cevap

$qunt = 0; 
$result = mysql_query("SELECT *  
                         FROM properties_items  
                        WHERE user_propid='$view'  
                     ORDER BY id DESC") or die (mysql_error());  

while ($row = mysql_fetch_array($result)) {  
  $itemid = $row['itemid']; 
  $qunt += $row['qunt'];  
} 

echo $qunt;

Ben muhtemelen kod ayarlamak bir sonucu ile döngü hiçbir nokta yoktur, bu durumda itemid kullanarak olmadığını söylemek cesaret. Bunun yerine, böyle bir şey deneyin:

$qunt = mysql_query "SELECT SUM(qunt) FROM properties_items WHERE user_propid='$view'";
$qunt += $row['qunt'];

Ve + + hattının kurtulmak.