title: CODEIGNITER - Message: Trying to get property of non-object
body: <p>I got the following message: </p>
  
  <p>A PHP Error was encountered</p>
  
  <p>Severity: Notice</p>
  
  <p>Message: Trying to get property of non-object</p>
  
  <p>Filename: models/usermodel.php</p>
  
  <p>Line Number: 4146</p>
  
  <p>and here is my function where the line 4146 is: </p>
  
  <pre><code>else if($resultRes-&gt;average&lt;'3' &amp;&amp;  $resultRes-&gt;average&gt;='2')
  </code></pre>
  
  <p>This is the full function code. I have the same message for line 4137, 4140, 4143, 4146 and 4149</p>
  
  <pre><code>function get_Ranking($resid=''){
  $sql="select ((Qrating+Srating+Drating+Crating)/4) as average from testimonial where RestId=".$resid;
  $query=$this-&gt;db-&gt;query($sql);
  $resultRes=$query-&gt;row();
  if($resultRes-&gt;average == '5'){
  return '050';
  }
  else if($resultRes-&gt;average&lt;'5' &amp;&amp;  $resultRes-&gt;average&gt;='4'){
  return '040';
  }
  else if($resultRes-&gt;average&lt;'4' &amp;&amp;  $resultRes-&gt;average&gt;='3'){
  return '030';
  }
  else if($resultRes-&gt;average&lt;'3' &amp;&amp;  $resultRes-&gt;average&gt;='2'){
  return '020';
  }
  else if($resultRes-&gt;average&lt;'2' &amp;&amp;  $resultRes-&gt;average&gt;='1'){
  return '010';
  }
  
  else{
  return '000';
  }
  }
  </code></pre>
  
  <p>How can i fix it?</p>