我坚持不懈,希望你们提供一些帮助。我正在构建一个奇幻游戏,其中具有以下结构的奇幻团队表,其中将使用从玩家表生成的唯一ID保存每个玩家。这是我的球员桌
playerID | playerName | teamID | value | point
13 peter Cech 2 8 0
15 Fernando Torres 2 9 0
这是我的幻想队桌子
teamID | fantasyteam | userID | GK1 | GK2 | DEF1 | DEF2 | MID1 | MID2 | FWD1 | FWD2
95 Washindi FC 1 13 2 3 6 7 12 15 18
我要实现的是将
fantansyteam
表与玩家表结合在一起,其中键将是幻想团队表中玩家的ID。这是我的模特:- 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();
}
这是我的控制器:-
public function user($userID)
{
$this->load->model('team_model');
$data['myteam']=$this->team_model->get_fantansy_team($userID);
$this->load->view('myteam_view',$data);
}
这是我的看法:-
<?php echo "<pre>" ;print_r($myteam);echo "</pre>" ;?>
<?php foreach($myteam as $player):
echo $player['GK1'] ;
echo $player['playerName'] ;
endforeach;?>
有人可以帮助我如何在我的视图中显示
playerName
和其他字段的用户团队吗? 最佳答案
您可以尝试一下,看看会得到什么:
function get_fantansy_team($userID){
$where=array(
'userID'=>$userID,
);
$this->db->select('P1.playerName, P2.playerName, FT.fantasyteam');
$this->db->from('fantasyteam AS FT'); //corrected table name
$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();
}
关于php - Codeigniter连接多个ID并显示到 View ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24485911/