Hi,
How can I add up all the numeric data in a specific column if I specify to only select the numeric data that equal to a specific value in another column.
For example
Table
1 | 10 | 99 | 1 | 11 | 99 | 2 | 12 | 99 | 2 | 13 | 99 |
Add up all data in "col2" where "col1" = "2" the the output answer whould be "25".
use an mysql_fetch_array to do it. select col2 from table where col1=2
then just use the array to perform the additions in a loop that ends when you run out of records. so for instance
(pseudo)
i = 0
while (array != end){
total += array i += 1 }
Can you show me a real life example/sample, im not the best coder in the world.
Im trying to use the following:
$sql = "SELECT Played FROM table_league WHERE Team='$TeamName'"; $result = mysql_query($sql); $mycol = mysql_fetch_array($result);
you can sum up the values with the sql query:
Based on the info in your first post:
SELECT SUM(col2) AS thesum WHERE col1=2
Thomas