title: Codeigniter: MySQL Where Clause and Quotes
body: <p><strong>Query in CodeIgniter</strong>:</p>
  
  <pre><code>$this-&gt;db-&gt;select('comments.created_at, comments.section_id, comments.submittedby_id, users.username, comments.text, sections.name');
  $this-&gt;db-&gt;order_by('comments.created_at', 'desc');
  $this-&gt;db-&gt;where('comments.submittedby_id',  'users.user_id'); 
  $this-&gt;db-&gt;where('comments.section_id', 'sections.id'); 
  
  $query = $this-&gt;db-&gt;get(array('comments', 'users', 'sections'),10);
  </code></pre>
  
  <p><strong>Produce SQL Request</strong>:</p>
  
  <blockquote>
    <p>SELECT <code>pdb_comments</code>.<code>created_at</code>,
    <code>pdb_comments</code>.<code>section_id</code>,
    <code>pdb_comments</code>.<code>submittedby_id</code>,
    <code>pdb_users</code>.<code>username</code>,
    <code>pdb_comments</code>.<code>text</code>,
    <code>pdb_sections</code>.<code>name</code> FROM
    (<code>pdb_comments</code>, <code>pdb_users</code>,
    <code>pdb_sections</code>) WHERE
    <code>pdb_comments</code>.<code>submittedby_id</code> =
    'users.user_id' AND
    <code>pdb_comments</code>.<code>section_id</code> =
    'sections.id' ORDER BY
    <code>pdb_comments</code>.<code>created_at</code> desc LIMIT
    10</p>
  </blockquote>
  
  <p>The issue is that the database prefix (<code>pdb_</code>) does not get added in the <code>WHERE</code> clause. I can manually insert the prefix by appending <code>$this-&gt;db-&gt;dbprefix</code>, but this doesn't fix the main problem.</p>
  
  <p><strong>Quotes</strong>:</p>
  
  <pre><code>`pdb_comments`.`submittedby_id` = 'pdb_users.user_id'
  </code></pre>
  
  <p>The quotes on the right side are not accurate, and generate 0 results for me. Is there any way to make CodeIgniter recognize the second half of the where clause as a piece of my table; thereby adding the database prefix, and properly placing the quotes by avoiding two joins? Is there another way to do this? Thanks in advance.</p>
  
  <p>--</p>
  
  <p>Jon</p>