选择使用加入Codeigniter

时间:2016-01-22 01:46:55

标签: codeigniter select join

我对使用codeigniter中的连接选择了一个问题:

我有2张桌子。

table game
id | id_team1 | id_team2
99 |    1     |    2

table team
id | team
1  | Real
2  | Barcelona

我想让球队重新登场:Real x Barcelona

我也选择了这个:

$this->db->select('game.*, team.team AS team_name1, team.team AS team_name2');
$this->db->from('game');   
$this->db->join('team', 'team.id = game.id_team1');   

这样我可以先退回团队,但不能退回第二个团队,反之亦然,将联接更改为jogo.id_team2

我必须像我的加入一样返回两队,否则我该怎么办?

谢谢!

1 个答案:

答案 0 :(得分:0)

试试这个

$this->db->select('game.*, team1.team AS team_name1, team2.team AS   team_name2');
$this->db->from('game');   
$this->db->join('team as team1', 'team1.id = game.id_team1'); 
$this->db->join('team as team2', 'team2.id = game.id_team2');