我正在尝试将int与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'];
$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;
我敢说您可能没有使用itemid,在这种情况下,循环遍历代码中的结果集没有任何意义。而是尝试这样的事情:
$qunt = mysql_query "SELECT SUM(qunt) FROM properties_items WHERE user_propid='$view'";
关于php - 试图显示在PHP的MySQL总数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2083819/