title: Call to a member function num_rows() on a non-object
body: <p>I'm using CodeIgniter, and I want to get some data from a table in a database.</p>
  
  <p>in my Model, I have this function :</p>
  
  <pre><code>public function fetch_cours($limit, $start, $element) {
  
          $id_element = $this-&gt;db-&gt;from('element')
                                 -&gt;where('name',$element)
                                 -&gt;limit(1)
                                 -&gt;get()
                                 -&gt;result();
  
          $query = $this-&gt;db-&gt;from('cour')
                             -&gt;where('id_element',(int) $id_element[0]-&gt;id)
                             -&gt;limit($limit, $start)
                             -&gt;get()
                             -&gt;result();
          var_dump($query);
  
          if ($query-&gt;num_rows() &gt; 0) {
              foreach ($query-&gt;result() as $row) {
                  $data[] = $row;
              }
              return $data;
          }
          return false;
     }
  </code></pre>
  
  <p>I want this function to return some records in the <code>cour</code> table.</p>
  
  <p>In my controller I have this line :</p>
  
  <pre><code>$cours = $this-&gt;cours_m-&gt;fetch_cours(10,0,'Programmation Orientée Objet (Java)');
  </code></pre>
  
  <p>When I call my controller I get this message :</p>
  
  <p><img src="https://i.stack.imgur.com/xPRIk.png" alt="enter image description here"></p>
  
  <p>The line 38 is : <code>if ($query-&gt;num_rows() &gt; 0) {</code></p>
  
  <p>So I did a var_dump($query) and this is the output :</p>
  
  <p><img src="https://i.stack.imgur.com/EfNbY.png" alt="enter image description here"></p>
  
  <p>What's the problem ? and how can I solve it ?</p>