[eluser]Jay Logan[/eluser]
Hello. I have a database which shows athlete names and athlete points for sporting events. All events are in 1 big table. And I want to tally up team points, based on the athletes `teamname` and for a specific `meet_id` to display. So far, I have successfully gotten the page to display all the teams that participated in the `meet_id`. I have been trying to show the team points next to the team name but it only shows the word "Array". Here is the code I'm using.
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){
$sql = "SELECT SUM(teampoints) FROM ievents WHERE meet_id = ? AND teamname = ? ORDER BY teampoints ASC LIMIT 5";
$q = $this->db->query($sql,array($id,$teamname));
return $q->result();
}
VIEW
Code:
<table class="table" border="0" cellpadding="0" cellspacing="0">
<tr>
<th>Team Scores</th>
</tr>
<? foreach ($teams as $team): ?>
<tr>
<td><? echo $team['teamname'] ?> - <? echo $teampoints ?></td>
</tr>
<? endforeach; ?>
</table>
CONTROLLER
Code:
function meet($id){
$meeting = $this->results_model->get_header($this->host,$id);
$this->set('meet_name', $meeting['meetname']);
$this->set('meeting', $meeting);
$evts = $this->results_model->get_events($id);
$events = array();
foreach ($evts as $event){
$events[$event['eg']][$event['type']][$event['eventcode']]['name'] = $this->code2string($event['eventcode'],$event['type']);
}
$this->set('events',$events);
$teams = $this->results_model->get_team_names($id);
$this->set('teams',$teams);
$teampoints = $this->results_model->get_team_points($id, 'Lane College');
$this->set('teampoints',$teampoints);
$this->load_view('results/meet');
}
Any help you can provide with this would be appreciated. I really want to learn from my mistakes.