如何从sql查看php的总价格?
实施例: SQL
Item Price
Phone1 1200
Phone2 1341
Phone3 2140
Phone4 850
Phone5 903
---------
Total Price: 6434
答案 0 :(得分:0)
您可以在SQL中获取sum()
SELECT sum(Price) FROM table
PHP中的
$sum = 0;
while($row = mysql_fetch_assoc($query)) {
$sum += $row['Price'];
}
答案 1 :(得分:0)
echo mysql_result(mysql_query("SELECT sum(Price) FROM table"), 0);