开发者

trying to show a total from mysql in php

I am trying to get the qunt with are int and add them all up and show a total

$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;


$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;

Dare I say that you probably aren't using the itemid, in which case there's no point in looping through a result set in code. Instead, try something like this:

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


$qunt += $row['qunt'];

And get rid of the ++ line.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜