SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Hybrid View
-
Sep 4, 2001, 13:05 #1
- Join Date
- Jul 2001
- Location
- cheshire
- Posts
- 83
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How do I sum the numbers in a field
I would like to add up the scores in a column in my table. I would like a little advice on the best way to do this. I have looked in the manual and see there is a function called array_sum(array arr). Would I be able to use this on the resulr set that comes back from a query which fetches the values from the column called 'scores'.
When I get the basics of this working, I would like to go one step further and sum only some of the values in the column e.g. sum only those values that correspond to the chemistry test and not the physics test. For reasons which I can't quite remember, I found it more convenient to store test results from more than one type of test in the same column. I have another column called 'testname' which identifies the test as chemistry or physics. I think you can put something like 'WHERE testname LIKE '%Chemistry%' as a clause to limit what the query returns - is that correct.
-
Sep 4, 2001, 22:05 #2
- Join Date
- Aug 2001
- Location
- Kent, Ohio
- Posts
- 367
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Maybe I'm not understanding your question completely.. but perhaps this can be of use to you:
I've always used the sum() function to sum up the columns:
PHP Code:$query = mysql_query("select sum(scores) as g from tablename where argument");
echo mysql_result($query,"g",0);
-
Sep 6, 2001, 22:03 #3
- Join Date
- Aug 2000
- Location
- Singapore
- Posts
- 411
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I would like to do something like his, but sum up all the records in several columns. How do I do this and display it?
First Million Challenge - Blog Challenge To Make My First Million
Active-Income.com | Active Jokes | Active-Freebies.com | Active Free Stuff
-
Sep 7, 2001, 02:44 #4
- Join Date
- Sep 2001
- Location
- Glasgow, Scotland
- Posts
- 2
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:$blah = mysql_fetch_array(mysql_query("SELECT sum(column1+column2) AS total FROM TABLE"));
signature
Bookmarks