I want to create a table of which a column will contain numeric values.
I want to sum up the numeric values and display them as total amount.
Example:
Mango = 100 Banana = 200 Total = 300
I do not know how to do it using php/mysql. Please help me.
Sometimes the simplest solutions are the best solutions...
Set a var to zero: $iTotal = 0; Whenever you print a row of the table, add the value for the column to that var: $iTotal += $value_from_column; When you printed the last row, print the total: echo $iTotal;
A forum, a FAQ, what else do you need?
Hi,
you could do this with a mySQL query: SELECT SUM({column}) FROM {table} More information here: http://www.mysql.com/doc/G/r/Group_by_functions.html
firemouse2001
true, but then you'd have to run a second query, which is bound to be slower than just adding the results you got from the first query.