title: Codeigniter error Message: Call to a member function result() on null
body: <p>I Keep getting this error and do not understand what is wrong, When a user search a string it should return all messages containing that string. </p>
  
  <p>This is my controller for search : </p>
  
  <pre><code>public function doSearch() {
  $this-&gt;load-&gt;model('Messages_model');
  $string = $this-&gt;input-&gt;get('string');
  $data['messages']=$this-&gt;Messages_model-&gt;searchMessages($string);
  $this-&gt;load-&gt;view('view_messages', $data);
  }
  </code></pre>
  
  <p>My doSearch function in messages_mdoel:</p>
  
  <pre><code>public function searchMessages($string) {
  $sql = "SELECT * FROM Messages WHERE text LIKE '%string%' ORDER BY posted_at DESC";
  $query = $this-&gt;db-&gt;query($sql,$string);
  
  if($query-&gt;num_rows() &gt; 0) {
  $messages = array();
  return $query;
  }
  
  }
  </code></pre>
  
  <p>and my view_messages:</p>
  
  <pre><code>&lt;?php foreach ($messages-&gt;result() as $message): ?&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;?php echo $message-&gt;posted_at; ?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $message-&gt;user_username; ?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $message-&gt;text; ?&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;?php endforeach; ?&gt;
  </code></pre>
  
  <p>Please help, thank you </p>