I have written the code below which is a I think is 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 statements. Can anyone 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