0

Good Morning,

I am writing code for a Hockey Pool site and I am working on the Standings page...typical divisional standings page.

My code runs through a loop for the four teams in each division and yields results for each team and outputs fine. Here is my problem...I want to sum the sums of the four teams.

For example, with Games Played it calculates the total GP for each team with the following chunk of code.

// GP
echo "</td><td width='40'align='center' bgcolor='FFFFFF'><font face='arial' size='2' color='000000'>";
$ttl_GP=$row['GP_wk1']+$row['GP_wk2']+$row['GP_wk3']+$row['GP_wk4']+$row['GP_wk5']+$row['GP_wk6']+$row['GP_wk7']+$row['GP_wk8']+$row['GP_wk9']+$row['GP_wk10']+$row['GP_wk11']+$row['GP_wk12']+$row['GP_wk13']+$row['GP_wk14']+$row['GP_wk15']+$row['GP_wk16']+$row['GP_wk17']+$row['GP_wk18']+$row['GP_wk19']+$row['GP_wk20']+$row['GP_wk21']+$row['GP_wk22']+$row['GP_wk23']+$row['GP_wk24']+$row['GP_wk25']+$row['GP_wk26'];
echo $ttl_GP;

This outputs a result of Team 1 - 57, Team 2 - 57, Team 3 - 58, Team 4 - 60.

I would now like to be able to sum these in final row to yield a result of 232.

Here is what I have tried but it echos "0". I think my syntax may be off.

$div_GP=$ttl_GP[$row['Team']]+$ttl_GP[$row['Team']]+$ttl_GP[$row['Team']]+$ttl_GP[$row['Team']];

Any help would be appreciated.

Edited by ceeandcee: n/a

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by ceeandcee
0

You're adding the same value over and over again $row['Team'] Assuming each team has their own names (Team1, Team2, Team3 etc) then you could try this:

$div_GP=$ttl_GP[$row['Team1']]+$ttl_GP[$row['Team2']]+$ttl_GP[$row['Team3']]+$ttl_GP[$row['Team4']];

All I've done is add numbers to each.

0

Thanks...I think we are close...but it is not finding a value for each team and thus adding 0+0+0+0 to give 0. I will keep playing around.

0

I think I will update the database with the summed total and then echo the sum of that column and that will make it work. Thanks for your help.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.