I'm trying to get this query to work in CodeIgniter but it's spitting out an error:
A Database Error Occurred Error Number: 1096
No tables used
SELECT *
If I put the query directly into MySQL it works fine (I replace the $variables with values). Here is the query as input into codeigniter:
$this->db->query("
SELECT *
FROM writing_quests
LEFT OUTER JOIN members_quests_completed
ON members_quests_completed.quest_id = writing_quests.id
WHERE writing_quests.level_required <= $userlevel
AND (
members_quests_completed.user_id = $user_id
OR
members_quests_completed.user_id IS NULL )"
);
$query = $this->db->get();
Am I doing something that is wrong and I am missing it? I've included the whole function call in case the problem is somewhere else? I've done this exact thing many times without an issue.
function get_all_quests_for_user() {
$user_id = $this->session->userdata('user_id');
$userlevel = $this->session->userdata('user_level');
$this->db->query("SELECT writing_quests.id, writing_quests.points_availible, writing_quests.name, writing_quests.note, writing_quests.instructions, writing_quests.time_limit, members_quests_completed.location_completed, members_quests_completed.status FROM writing_quests LEFT OUTER JOIN members_quests_completed ON members_quests_completed.quest_id = writing_quests.id WHERE writing_quests.level_required <= '$userlevel' AND writing_quests.unlocked = 1 AND ( members_quests_completed.user_id = '$user_id' OR members_quests_completed.user_id IS NULL )");
$query = $this->db->get();
$this->db->last_query();
return $query->result();
}
query()
method doesn't like line breaks. – Eweneck