Welcome Guest, Not a member yet? Register   Sign In
Having Trouble Linking Values of 2 Functions
#1

[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>

&lt;? foreach ($teams as $team): ?&gt;
<tr>
<td>&lt;? echo $team['teamname'] ?&gt;</td><td>&lt;? echo $teampoints ?&gt;</td>
</tr>
&lt;? endforeach; ?&gt;
</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!


Messages In This Thread
Having Trouble Linking Values of 2 Functions - by El Forum - 09-29-2008, 08:49 AM
Having Trouble Linking Values of 2 Functions - by El Forum - 09-29-2008, 09:18 AM
Having Trouble Linking Values of 2 Functions - by El Forum - 09-29-2008, 09:43 AM
Having Trouble Linking Values of 2 Functions - by El Forum - 09-29-2008, 09:52 AM
Having Trouble Linking Values of 2 Functions - by El Forum - 09-29-2008, 10:06 AM
Having Trouble Linking Values of 2 Functions - by El Forum - 09-29-2008, 11:25 AM
Having Trouble Linking Values of 2 Functions - by El Forum - 09-29-2008, 11:37 AM
Having Trouble Linking Values of 2 Functions - by El Forum - 09-29-2008, 12:13 PM
Having Trouble Linking Values of 2 Functions - by El Forum - 09-29-2008, 12:33 PM
Having Trouble Linking Values of 2 Functions - by El Forum - 09-29-2008, 12:39 PM
Having Trouble Linking Values of 2 Functions - by El Forum - 09-29-2008, 12:42 PM
Having Trouble Linking Values of 2 Functions - by El Forum - 10-03-2008, 07:32 AM



Theme © iAndrew 2016 - Forum software by © MyBB