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.
LVL 1
debbieau1Asked:
Who is Participating?
 
Saqib KhanConnect With a Mentor Senior DeveloperCommented:
Should be...

$query = "SELECT amount, sum(amount) as Total
               FROM mytable Group by amount";
0
 
alexhoganCommented:
You can do this in your SQL query;

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 .....

}
0
 
debbieau1Author Commented:
This worked well thanks a lot.  I had worked out to use the sum, but was grouping on the wrong field.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.