寻求在CodeIgniter中加入查询的帮助

时间:2013-11-14 10:38:29

标签: php mysql codeigniter activerecord

我在连接两个activerecord查询时遇到问题。未注释的代码显示实际工作的内容,注释掉的代码显示我认为应该是代码的内容。显然,注释掉的代码需要在循环中。

$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 个答案:

答案 0 :(得分:1)

您的加入查询应该是这样的

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

除非在此处发布查询时这是您身边的拼写错误