简体   繁体   English

Codeigniter活动记录Join 2 x From in语句

[英]Codeigniter Active record Join 2 x From in statement

Hi Have written the code below which is a I think a simple select with a join. 嗨,我已经写了下面的代码,我认为这是一个简单的选择。

    $this->db->select('PAS_User.user_first_name, PAS_User.user_last_name, PAS_User.user_avatar_url, AMS_Notification.noti_entitiy_id, AMS_Notification.noti_entity_type, AMS_Notification.noti_updated FROM AMS_Notification INNER JOIN PAS_User ON AMS_Notification.noti_from_user_id = PAS_User.user_user_id');
    $this->db->from('AMS_Notification');
    $this->db->join('PAS_User', 'PAS_User ON AMS_Notification.noti_from_user_id = PAS_User.user_user_id');
    $this->db->where('AMS_Notification.noti_to_user_id', $userid);
    $this->db->order_by("noti_updated", "desc");

    $query = $this->db->get('AMS_Notification');

    if($query -> num_rows() == 1) {
        return $query->result();
    } else {
        return false;
    }

However when I call the page it shows this query with two from stamens, can any one tell me what I am doing wrong here? 但是,当我调用该页面时,它显示了带有两个雄蕊的查询,有人可以告诉我我在做什么错吗?

SELECT `PAS_User`.`user_first_name`, `PAS_User`.`user_last_name`, `PAS_User`.`user_avatar_url`, `AMS_Notification`.`noti_entitiy_id`, `AMS_Notification`.`noti_entity_type`, `AMS_Notification`.`noti_updated` FROM AMS_Notification INNER JOIN PAS_User ON AMS_Notification.noti_from_user_id = PAS_User.user_user_id FROM (`AMS_Notification`, `AMS_Notification`) JOIN `PAS_User` ON `PAS_User` `ON` AMS_Notification.noti_from_user_id = PAS_User.user_user_id WHERE `AMS_Notification`.`noti_to_user_id` = '7' ORDER BY `noti_updated` desc
$this->db->select('PAS_User.user_first_name, PAS_User.user_last_name, PAS_User.user_avatar_url, AMS_Notification.noti_entitiy_id, AMS_Notification.noti_entity_type, AMS_Notification.noti_updated');
$this->db->from('AMS_Notification');
$this->db->join('PAS_User', 'AMS_Notification.noti_from_user_id = PAS_User.user_user_id');
$this->db->where('AMS_Notification.noti_to_user_id', $userid);
$this->db->order_by("noti_updated", "desc");

$query = $this->db->get();

if($query -> num_rows() == 1) {
    return $query->result();
} else {
    return false;
}

No need to specify table name and JOIN in select part 无需在选择的部分中指定表名和JOIN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM