[eluser]Jay Logan[/eluser]
I am trying to show a table with a team name in column 1 and the team points in column 2. I can acheive showing the names in column 1. But when I attempt to show the points in column 2, it only shows the points for the 1st team on the list and then gives those points to each team in the list. So the same point value is shown for all teams. Here the the code I'm using. I figured the problem lies in the controller somewhere but I'm such a noob.
MODEL
Code:
function get_team_names($id){
$sql = "SELECT DISTINCT teamname FROM ievents WHERE meet_id = ?";
$q = $this->db->query($sql,array($id));
return $q->result_array();
}
function get_team_points($id, $teamname) {
$this->db->select_sum('teampoints','points');
$this->db->from('ievents');
$this->db->where('meet_id',$id);
$this->db->where('teamname',$teamname);
$query = $this->db->get();
return $query->row()->points;
}
VIEW
Code:
<table class="table" border="0" cellpadding="0" cellspacing="0">
<tr>
<th colspan="2">Team Scores</th>
</tr>
<? foreach ($teams as $team): ?>
<tr>
<td><? echo $team['teamname'] ?></td><td><? echo $teampoints ?></td>
</tr>
<? endforeach; ?>
</table>
CONTROLLER
Code:
$teams = $this->results_model->get_team_names($id);
foreach ($teams as $team){
$teampoints = $this->results_model->get_team_points($id, $team['teamname']);
}
$this->set('teampoints',$teampoints);
$this->set('teams',$teams);
Please help!