Adding multiple mysql row records

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

Adding multiple mysql row records

Post by tomsace »

Hi,
I have a database set out like this:

User - # of times played
User1 - 13
User2 - 21
User3 - 92 etc...


I would like to know how to add all the # of times played together?
Thanks in advanced.
anantha
Forum Commoner
Posts: 59
Joined: Thu Dec 23, 2010 7:38 pm

Re: Adding multiple mysql row records

Post by anantha »

when you use mysql to get the content..i assume the db is mysql....you will get an array...use array_count_values($array)...u will get the sum
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Adding multiple mysql row records

Post by John Cartwright »

Code: Select all

SELECT SUM(`your_count_column`) AS `times_played` FROM `your_count_table`
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

Re: Adding multiple mysql row records

Post by tomsace »

Got it working beautifully, thanks alot :)
Post Reply