Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Addition in database data...

Codes here !

Moderators: macek, egami, gesf

Addition in database data...

Postby Scoodo » Sun Aug 26, 2012 10:57 am

Not sure how to explain this but here goes an attempt...

I've got a table where I have 3 user names. Scoodo, Scoobii, and Skadda. They have all taken tests. test 1, test 2 and test 3. In each test they have scored 0-100, and what I'm trying to do is run the data from a data base where I have the following rows of data,


Name: test: Result:

Scoodo test 1 76
Scoodo test 2 83
Scoodo test 3 21
Scoobii test 1 71
Scoobii test 2 79
Scoobii test 3 47
Skadda test 1 38
Skadda test 2 49
Skadda test 3 93


What I want is to be able to take this data, and have the following output, but I'm not sure how to do this, can anyone point me in the right direction?


Output wanted,
Name: Total Result:
Skadda 144
Scoodo 255
Scoobii 233

Not sure if this is something I do in the SQL statement at the top of the page for querying the database, and organising data, or if I need to build in an IF statement when echo'ing the data out of the data, and into the page.

Can anyone assist me with this?
Scoodo
New php-forum User
New php-forum User
 
Posts: 22
Joined: Tue Mar 20, 2012 12:09 pm

Re: Addition in database data...

Postby NigelRen » Sun Aug 26, 2012 11:04 pm

You can use SQL - simply
Code: Select all
select name, sum(result)
    from tableName
    group by name;
NigelRen
php-forum Active User
php-forum Active User
 
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am

Re: Addition in database data...

Postby Scoodo » Tue Aug 28, 2012 12:19 pm

I've moved forward because of what you've posted, which is great. Thank you NigelRen. I found the following article which has worked nicely,

http://www.w3schools.com/sql/sql_groupby.asp

just for anyone who has this issue in future.
Scoodo
New php-forum User
New php-forum User
 
Posts: 22
Joined: Tue Mar 20, 2012 12:09 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron