In the following code I have values in the eto_rpoints_lkup table that I want to match on team_id.
These values have a rp_id of 1, 2, or 3.
1 = Fuel Point
2 = Manpower
3 = Munitions
I need to SUM all the values for each rp_id for each team_id.
Example on two records
rp_id = 1 which means Fuel
team_id is 127 for both records
r_points for one record is 3 and the other is 4
So I need $fuelpoints to total 7 for that team.
$sql = $db->sql_query("SELECT * FROM " . $prefix . "_tc_ladderteams tclt
JOIN " . $prefix . "_tc_teams tct ON (tclt.team_id = tct.team_id)
LEFT JOIN " . $prefix . "_eto_territories et ON (tct.tid = et.tid)
LEFT JOIN " . $prefix . "_eto_divisions ed ON (tct.div_id = ed.div_id)
JOIN " . $prefix . "_tc_ladders tcl ON (tclt.ladder_id = tcl.sid)
LEFT JOIN " . $prefix . "_eto_rpoints_lkup erl ON (erl.team_id = tclt.team_id)
WHERE enabled = 1 AND (ed.div_commander = '$nukeusername' || ed.div_xo ='$nukeusername')
ORDER BY 'name'");
while ( $row = $db->sql_fetchrow($sql) ) {
$team_id = $row['team_id'];
$team_name= stripslashes($row['name']);
$t_name= stripslashes($row['t_name']);
$fuelpoints = $row['fuel_pt'];
$munitionpoints = $row['munition_pt'];
$manpowerpoints = $row['manpower_pt'];
echo"<tr>"
. "<td align=\"center\" bgcolor=\"#666666\"><font color=\"#000000\">$team_name</font></td>"
. "<td align=\"center\" bgcolor=\"#666666\"><font color=\"#000000\">$fuelpoints</font></td>"
. "<td align=\"center\" bgcolor=\"#666666\"><font color=\"#000000\">$munitionpoints</font></td>"
. "<td align=\"center\" bgcolor=\"#666666\"><font color=\"#000000\">$manpowerpoints</font></td>"
. "<td align=\"center\" bgcolor=\"#666666\"><font color=\"#000000\">$t_name</font></td>"
. "<td align=\"center\" bgcolor=\"#666666\"><font color=\"#000000\">[ <a href=\"modules.php?name=Campaign&file=Reenforce&team_id=$team_id\">" . _CLICK . "</a>]</td>"
. "</tr>";
}