Reputation: 75
I have a Table in MySQL that stores data as such:
Name Amount Time
Person 1 1 Time
Person 2 1 Time
Person 3 1 Time
Person 1 1 Time
Person 2 1 Time
Person 3 1 Time
Person 1 1 Time
I want to echo these reults so they would add all the 'amounts' together and put the final number with the persons name so it would appear as:
Person 1 3 Time
Person 2 2 Time
Person 3 2 Time
How can I do this in PHP? Thank you.
Upvotes: 0
Views: 43
Reputation: 91734
You should do that in sql instead of in php.
Something like:
SELECT `Name`, SUM(`Amount`) as total, `Time` FROM `your_table` GROUP BY `Name`
Upvotes: 1