Simple php/mysql maths

Associate
Joined
19 Jun 2006
Posts
162
Location
Swansea, Wales
I am so hungover so it's probably not the best time to be trying to remember php so if you guys can help me out here i would be very grateful!

I have a table with a number of entries for scores. I want to add these up and display a total with a view to eventually sorting each entry in to who had the highest score.

MySQLTable
Name Score1 Score2 Score3
A 1 2 4
B 3 5 1

So i want to query the table, add up score1, 2 and 3 and display the total.

Help please! :)
 
Code:
$result = mysql_query("
SELECT
( score1 + score2 + score3 ) AS total, name
FROM scores
");

while ( $row = mysql_fetch_assoc($result) ) {
    echo "Name: {$row['name']}. Score: {$row['total']}.<br />";
}
 
I have lots of other fields i want to select other than just name. Is there a quick way to select all or do i have to write out the name of every field?
 
Back
Top Bottom