I'm stuck on something and would appreciate some help from you guys. I am building a fantasy game where I have fantasy team table with the below structure where each player will be saved with a unique ID generated from players table. Here is my player table
playerID | playerName | teamID | value | point
13 peter Cech 2 8 0
15 Fernando Torres 2 9 0
and here is my fantasyteam table
teamID | fantasyteam | userID | GK1 | GK2 | DEF1 | DEF2 | MID1 | MID2 | FWD1 | FWD2
95 Washindi FC 1 13 2 3 6 7 12 15 18
what I want to achieve is joining fantansyteam
table with player table in which the keys will be the ids of players in fantasy team table. Here is my model :-
function get_fantansy_team($userID){
$where=array(
'userID'=>$userID,
);
$this->db->select();
$this->db->from('fantansyteams AS FT');
$this->db->join('player AS P1', 'FT.GK2= P1.playerID');
$this->db->join('player AS P2', 'FT.GK1= P2.playerID','left outer');
$this->db->where('FT.userID', $userID);
$query = $this->db->get();
return $query->result_array();
}
Here is my controller :-
public function user($userID)
{
$this->load->model('team_model');
$data['myteam']=$this->team_model->get_fantansy_team($userID);
$this->load->view('myteam_view',$data);
}
And here is my view :-
<?php echo "<pre>" ;print_r($myteam);echo "</pre>" ;?>
<?php foreach($myteam as $player):
echo $player['GK1'] ;
echo $player['playerName'] ;
endforeach;?>
Can someone help me how to display user team with the playerName
and other fields in my view?