2013-11-14 67 views
0

我無法將兩個activerecord查詢結合在一起。未註釋的代碼顯示實際工作的內容,註釋掉的代碼顯示我認爲應該是代碼的內容。顯然,註釋掉的代碼需要在循環中。在CodeIgniter中尋求幫助加入查詢

$musicQuery = "album1,album2,album3,album4"); 

$albums = explode(",", $musicQuery); 
foreach($albums as $i => $album) { 

    $albumQuery = $this->db->get_where('albums', array('id' => $album), 1)->row_array();         

    $artistQuery = $this->db->get_where('artists', array('tc_id' => $albumQuery['artist']), 1)->row_array(); 

    echo $artistQuery['artist'].'<br>'; 
} 

// This is what I thought I would need 
//$this->db->select('*'); 
//$this->db->from('albums'); 
//$this->db->join('artists', 'artists.id = albums.artist'); 
//$this->db->where('id', $album); 
//$this->db->limit(1);        
//$this->db->order_by("post_views", "desc"); 
//$artistQuery = $this->db->get(); 

回答

1

你的連接查詢應該是這樣的

$this->db->join('artists', 'artists.tc_id = albums.artist'); 

除非那個人是從你身邊一個錯字,而在這裏張貼查詢