2016-01-22 70 views
0

我对使用codeigniter加入的选择有疑问:在Codeigniter中选择加入

我有2个表格。

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

table team 
id | team 
1 | Real 
2 | Barcelona 

我要回队安装摊牌:真正的X巴萨

我选择这个问题,以及:

$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

我必须返回这两个团队,因为我的加入或否则我该怎么办?

谢谢!

回答

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'); 
+0

喜bekt 准确,更容易比我想象的,但不能 非常感谢您! – Flybow