0

2 つのアクティブ レコード クエリを結合するのに問題があります。コメントを外したコードは実際に機能するものを表示し、コメントを外したコードは私が本来あるべきコードだと思ったものを表示します。明らかに、コメントアウトされたコードはループ内にある必要があります。

$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();
4

1 に答える 1

1

結合クエリは次のようになります

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

ここにクエリを投稿するときにそれがあなたの側からのタイプミスでない限り

于 2013-11-14T10:48:02.427 に答える