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.

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.

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.