title: CodeIgniter MySQL query not working
body: <p>I'm trying to get this query to work in CodeIgniter but it's spitting out an error:</p>
  
  <blockquote>
    <p>A Database Error Occurred Error
    Number: 1096</p>
    
    <p>No tables used</p>
    
    <p>SELECT *</p>
  </blockquote>
  
  <p>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:</p>
  
  <pre><code>$this-&gt;db-&gt;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 &lt;=  $userlevel 
      AND ( 
          members_quests_completed.user_id = $user_id
          OR 
          members_quests_completed.user_id IS NULL )"
  );
  $query = $this-&gt;db-&gt;get();
  </code></pre>
  
  <p>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.</p>
  
  <pre><code>function get_all_quests_for_user() {
      $user_id = $this-&gt;session-&gt;userdata('user_id');
      $userlevel = $this-&gt;session-&gt;userdata('user_level');
  
      $this-&gt;db-&gt;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 &lt;=  '$userlevel' AND writing_quests.unlocked = 1 AND ( members_quests_completed.user_id = '$user_id' OR members_quests_completed.user_id IS NULL )");
      $query = $this-&gt;db-&gt;get();
      $this-&gt;db-&gt;last_query();
      return $query-&gt;result();
  }
  </code></pre>