Reputation: 311
I'm having trouble joining two activerecord queries together. The uncommented code displays what actually works and the commented out code displays what I thought should be the code. Obviously the commented out code needs to be in the loop.
$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();
Upvotes: 0
Views: 36
Reputation: 1447
Your join query should be something like this
$this->db->join('artists', 'artists.tc_id = albums.artist');
Unless that was an typo from your side while posting the query here
Upvotes: 1