I have this table:
ID SUM
1 2
2 5
3 3
There is any function to give me the total of SUM column:
2+5+3=10
I can calculate them using math such as $i=$i+$row[sum] .. but I ask about function to do that auto.
Thanks...
Printable View
I have this table:
ID SUM
1 2
2 5
3 3
There is any function to give me the total of SUM column:
2+5+3=10
I can calculate them using math such as $i=$i+$row[sum] .. but I ask about function to do that auto.
Thanks...
you could put those into an array and then add them that way using array_sum()
or when you pull them out of the DB you can add them to each other like you are doing.
I think you can also use:
select sum(columnName) as variable from table;
You can use that query and i think the value will be stored in the variable $variable.
or just run a loop that will add them together. I'll post an example in a moment ;)
wouldn't something like this work:?PHP Code:$x = 0;
$the_sum = 0;
While ($x < mysql_num_rows($query))
{
$the_sum = $the_sum + mysql_result($query,$x,"sum");
$x++;
}
ECHO "Sum of row: $the_sum";
yup that could work but HeaveNGuY has the right idea. besides using mysql_result is a lot slower then using sum()