2016-08-23 4 views
3
function get_all_notification() { //get all notification based on the 'notification' table left join by 'membership' table 

    $this->db->select()->from('notification')->join('membership','membership.membership_id = notification.notif_id','left');   $notif = $this->db->get(); 
    return $notif->result(); 
} 

メンバーシップテーブルのフィールドを表示できません。codeigniterの左結合のアクティブレコードを使用して、2つの異なるテーブルのフィールドを表示するにはどうすればよいですか?

+1

使用 –

+0

グッドラックと楽しみコーディングがありますか? –

+0

select()にメンバーシップの列名も入力する必要があります。select( 'notification。*、membership。*')と動作したら教えてください –

答えて

1

あなたは上から下までだクリーンなコードをしたいときには使用されている。この

function get_all_notification() { //get all notification based on the 'notification' table left join by 'membership' table 

    $this->db->select('*')->from('notification')->join('membership','membership.membership_id = notification.notif_id','left'); 
    $notif = $this->db->get(); 
    return $notif->result(); 
} 
0
function get_all_notification() 
{ 
    $this->db->select('n.*,m.*'); 
    $this->db->from('notification as n') 
    $this->db->join('membership as m','m.membership_id = n.notif_id','left'); 
    $notif = $this->db->get(); 
    return $notif->result(); 
} 

を試してみてください。しかし、あなたのコードを使用することは、矢印が連続しているところでは問題ありません。選択するフィールドを特定するのを忘れてしまっただけです。エイリアスを使用すると、特定のフィールドを選択するのにも効果的です。

ご覧のとおり、nとmを使用しました。これはnテーブルとmからすべてを選択するワイルドカードです。あなたが望むものを指定するときは、n.your_fieldとm.your_fieldを使うことができます。あなたは上記の代わりに、そのクエリ文字列を意味クールマインド@( 'membership.membership_id、membership.other_names、通知*を。')を選択D

関連する問題