Calculate and display the sum of all values in the 1st field mysql

The question was asked: 6 years 10 months ago   views: 6
0

Good evening, need naschitti and display the sum of all the values in the 1st field in mysql. How to do it better? to calculate directly in mysql or withdraw first and let php's counting?

Asked: Denis Masster Denis Masster 19-01-2012 в 23:32:01

Answers   1

4
SELECT SUM(field name) FROM table name WHERE condition

$row=mysql_fetch_array($result);
echo $row[0];
Answered: artem artem 19-01-2012 в 23:35:48
Thanks, but... $result=mysql_query("SELECT count(amount) FROM bank"); And then as $result bring? If echo directly, it displays Resource id #5. If you skip using mysql_fetch_array and then display - it turns out Array :) - Denis Masster Denis Masster 19-01-2012 в 23:41:10
The question you have is different, well to think a little and write the code. - artem artem 19-01-2012 в 23:50:25
Yes, I have already understood) but it brought out the number of rows, and I need the total field i.e. have two lines in the first 20 in the second and 5 in the amount necessary to 25 output :) - Denis Masster Denis Masster 19-01-2012 в 23:54:57
maybe something with the field type. write all fields with their types. - artem artem 19-01-2012 в 23:57:16
4 fields: id - int(10) name varchar, amount int(10) date - date - Denis Masster Denis Masster 19-01-2012 в 23:59:31