debbieau1
asked on
calculating total in Dreamweaver mysql php
I have a field "amount" and display many records (with a repeat region) I want to be able to add up all the total of the "amount" for all the records and put the total at the bottom.
I would be really grateful for any help here.
I would be really grateful for any help here.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This worked well thanks a lot. I had worked out to use the sum, but was grouping on the wrong field.
SELECT sum(amount) as Total
FROM mytable
Your php code would look something like this;
$query = "SELECT amount, sum(amount) as Total
FROM mytable";
$result = mysql_query($result) or die($err_msg);
while($row = mysql_fetch_array($result)
$amount = $row['amount'];
$total = $row['Total'];
print .....
}