title: Call to a member function num_rows() on boolean in PHP
body: <p>I am getting the below error on my code,</p>
  
  <pre><code>Call to a member function num_rows() on boolean in C:\xampp\htdocs\codeigniter\application\controllers\go.php on line 15
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>&lt;?php if (!defined('BASEPATH')) exit('No direct script access
  allowed');
  class Go extends MY_Controller {
  function __construct() {
  parent::__construct();
  $this-&gt;load-&gt;helper('string');
  }
  public function index() {
  if (!$this-&gt;uri-&gt;segment(1)) {
  redirect (base_url());
  } else {
  $url_code = $this-&gt;uri-&gt;segment(1);
  $this-&gt;load-&gt;model('Urls_model');
  $query = $this-&gt;Urls_model-&gt;fetch_url($url_code);
  if ($query-&gt;num_rows() == 1) {
  foreach ($query-&gt;result() as $row) {
  $url_address = $row-&gt;url_address;
  }
  redirect (prep_url($url_address));
  } else {
  $page_data = array('success_fail' =&gt; null,
  'encoded_url' =&gt; false);
  $this-&gt;load-&gt;view('common/header');
  $this-&gt;load-&gt;view('nav/top_nav');
  $this-&gt;load-&gt;view('create/create', $page_data);
  $this-&gt;load-&gt;view('common/footer');
  }
  }
  }
  }
  </code></pre>