title: A PHP Error was encountered Severity: Notice Message: Undefined variable: id Filename: models/singlequery_model.php Line Number: 4
body: <pre><code>A PHP Error was encountered
  
  Severity: Notice
  
  Message: Undefined variable: id
  
  Filename: models/singlequery_model.php
  
  Line Number: 4
  
  A Database Error Occurred
  
  Error Number: 1064
  
  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
  </code></pre>
  
  <p>SELECT * FROM patient WHERE id =</p>
  
  <p>Filename: C:\xampp\htdocs\login\system\database\DB_driver.php</p>
  
  <p>Line Number: 330</p>
  
  <p>Is this the right way to query a single result?</p>
  
  <pre><code>    &lt;?php
  class Singlequery_model extends CI_Model{
      function get_query(){
          $query = $this-&gt;db-&gt;query("SELECT * FROM patient WHERE id  = $id");
  
          if($query-&gt;num_rows() &gt; 0 ){
              foreach ($query-&gt;result() as $row){
                  $data[] = $row;
              }
              return $data;
          }
      }
  }
  </code></pre>
  
  <p>Below is my controller</p>
  
  <pre><code>    &lt;?php 
  class Site extends CI_Controller{
      function __construct(){
        parent::__construct();
        $this-&gt;is_logged_in();
        $this-&gt;load-&gt;model('site_model');
  
      }
      function delete(){
        $this-&gt;site_model-&gt;delete_row();
        redirect('site/members_area');
      }
  
      function view(){
  
          $this-&gt;load-&gt;model('singlequery_model');
  
          $data['records'] = $this-&gt;singlequery_model-&gt;get_query();
          $this-&gt;load-&gt;view('patient_update', $data);
  
      }
  </code></pre>
  
  <p>}</p>