SUM()函数不显示sum ...不返回任何记录

时间:2011-04-16 20:36:25

标签: php sql

好的......所以,我已经把所有内容写得正确了......但是,当试图获得SQL行“Total”的总计时,它不再给我一个错误......它只是返回空白

CODE
    $query2 = "SELECT SUM(Total) AS Total_Owed FROM public debts";
    $sum = mysql_query($query2);
    echo "<tr><td align=\"left\" colspan=\"2\">$" . $row['Total_Owed'] . "</td><td>&nbsp; </td></tr>";

当它运行时,它只显示:$,仅此而已。有什么建议吗?

2 个答案:

答案 0 :(得分:3)

执行mysql_query后,您还需要获取该行,因此请更改您的代码以包含此

$row = mysql_fetch_row($sum);

答案 1 :(得分:0)

您必须先检索查询结果:

<?php
$query2 = "SELECT SUM(Total) AS Total_Owed FROM public debts";
$objResults = mysql_query($query2);
$arrRow = mysql_fetch_assoc($objResults)
echo "<tr><td align=\"left\" colspan=\"2\">$" . $arrRow['Total_Owed'] . "</td><td>&nbsp; </td></tr>";