Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用codeigniter中左连接的活动记录显示两个不同表中的字段?_Php_Android_Mysql_Codeigniter - Fatal编程技术网

Php 如何使用codeigniter中左连接的活动记录显示两个不同表中的字段?

Php 如何使用codeigniter中左连接的活动记录显示两个不同表中的字段?,php,android,mysql,codeigniter,Php,Android,Mysql,Codeigniter,我无法显示成员资格表中的字段 试试这个 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 = n

我无法显示成员资格表中的字段

试试这个

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();
}
当您需要自上而下的干净代码时,可以使用此选项。但是如果箭头是连续的,那么使用代码就可以了。您只是忘记了确定要选择的字段。在选择特定字段时,使用别名也很有用

如您所见,我使用了n.*和m.*,这只是从n表和m中选择all的通配符。在指定所需内容时,可以使用n.your_字段和m.your_字段


Goodluck and have fun coding:D

使用select('membership.membership\u id,membership.other\u name,notification.*')@Kool记住,你是指查询字符串而不是上面的字符串吗?select()也应该用成员的列名填充尝试select('notification.*,membership.*),如果它对每个推荐评论都有效,请告诉我,或者回答,同样的话:)。我也回答了,只是代码稍微长一点,以便于查看。。这只是为了眼睛,但为每个人干杯:)@Jackskie这对你有帮助吗。如果有其他建议,请告诉我
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();
}
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();
}