title: Pass a PHP variable to a MySQL query
body: <p>What is wrong with this code? I get an empty array. I am passing a PHP variable to the query, but it doesn’t work; when I give a hardcoded value the query returns a result.</p>
  
  <pre><code>echo $sub1 = $examSubject[$i];
  $subType = $examType[$i];
  $query = $this-&gt;db-&gt;query("select dSubject_id from tbl_subject_details where dSubjectCode='$sub1'");
  print_r($query-&gt;result_array());
  </code></pre>