簡體   English   中英

Codeigniter活動記錄Join 2 x From in語句

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

嗨,我已經寫了下面的代碼,我認為這是一個簡單的選擇。

    $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;
    }

但是,當我調用該頁面時,它顯示了帶有兩個雄蕊的查詢,有人可以告訴我我在做什么錯嗎?

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;
}

無需在選擇的部分中指定表名和JOIN

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM