doucheng7234 2014-02-25 09:01
浏览 47
已采纳

Codeigniter活动记录加入2 x来自语句

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
  • 写回答

1条回答 默认 最新

  • douji6896 2014-02-25 09:02
    关注
    $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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度