How To Sum goals

4 posts by 2 authors in: Forums > CMS Builder
Last Post: October 24, 2013   (RSS)

I hope to find a answer :-)

I have a football site and i would punt in it some stats

I have a table called Matches (num, team_a, team_b, goal_home, goal_away, season)

How can i sum total of goal home where "team_a is XX and season is XX"?

Thank you in advance for your help

Orazio 

hi have this code 

<?php
$totalGoalf = 0;
$matches = mysql_select('matches');

foreach ($matches as $matches) {
$totalGoalf += floatval($matches['goal_home']);
}


?><?php echo number_format($totalGoalf) ?>

but how can i limit result where to "team_a is XX and season is XX"

Ok solved :D

<?php 
$totalGoalf = 0; 
$matches = mysql_select('matches', "team_a = '1' AND season = " . intval($seasonRecord['num']));

foreach ($matches as $matches) { 
$totalGoalf += floatval($matches['goal_home']); 
}


?><?php echo number_format($totalGoalf) ?>