我正在PHP中运行以下mysql查询。
$result = mysql_query("SELECT SUM(profit) FROM customers;");
$sum_profit = mysql_num_rows($result);
echo $sum_profit;"
返回的响应$SUM_PROFIT始终为1。 在利润表中填入了以下内容:
profit
0.00
1.00
1.00
0.00
11.28
利润
列的类型是Double(10,2)
。 我是不是遗漏了什么?
mysql_num_rows()
返回查询返回的行数。 在本例中,它是一行。 您正在查找返回结果集的任何函数。 例如mysql_fetch_row()
。
$result = mysql_query("SELECT SUM(profit) FROM customers;");
$row = mysql_fetch_row($result);
echo $row[0];
试试这个;
$result = mysql_query("SELECT SUM(profit) as totalprofit FROM customers;");
$row = mysql_fetch_row($result);
echo $row[totalprofit];
希望有帮助