2016-01-22 64 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