开发者

trying to show a total from mysql in php

开发者 https://www.devze.com 2022-12-16 13:02 出处:网络
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 *

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

精彩评论

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

关注公众号