本文介绍了计算列中所有数字的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表,我想计算价格"列中所有值的总和,并回显结果.我已经看到MySQL语句SELECT sum(column)FROM table,但是我发现很难在PHP中使用它并回显结果.
I have a table that I want to calculate the sum total of all the values in column "Price" and echo the results. I have seen MySQL statement SELECT sum(column) FROM table but I am finding it difficult to use it in PHP and echo the results.
推荐答案
mysql_connect($hostname, $username, $password);
mysql_select_db($db);
$sql = "select sum(column) from table";
$q = mysql_query($sql);
$row = mysql_fetch_array($q);
echo 'Sum: ' . $row[0];
根据需要替换变量名称和表/列名称.
Replace variable names and table/column names as needed.
这篇关于计算列中所有数字的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!