title: Error Trying to get property of non-object and Undefined variable: Codeigniter
body: <p>I am facing the following error:</p>
  
  <blockquote>
    <p>Trying to get property of non-object and  Undefined variable php
    errors in my code</p>
  </blockquote>
  
  <p>Controller: </p>
  
  <pre><code>function showDoctorInformation(){
      $this-&gt;load-&gt;model('PatientModel');
      $data['doctorinfo'] = $this-&gt;PatientModel-&gt;getDoctorInformation();
      $this-&gt;parser-&gt;parse('patient_msgview', $data);
  
  }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>function getDoctorId() {
          $this-&gt;db-&gt;from('person');
          $this-&gt;db-&gt;select('doctorId');
          $doctorId = $this-&gt;db-&gt;get()-&gt;result();
          return $doctorId;
      }
  
  function getDoctorInformation() {
  
  
      $doctorId = $this-&gt;getDoctorId();
  
          $this-&gt;db-&gt;from('DoctorInfo');
          $this-&gt;db-&gt;where('doctorId', $doctorId);
          $this-&gt;db-&gt;select('name', 'surname', 'Bio', 'Address', 'img');
          $doctorinfo = $this-&gt;db-&gt;get()-&gt;result();
          return $doctorinfo;
  
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;?= $doctorinfo-&gt;name ?&gt;
  </code></pre>
  
  <p>I have displayed information from the database before with this method and I can't see the error now.</p>