title: Codeigniter Count / If
body: <p>this is taking me too long to figure out. I am using Codeigniter to query a database.
  The model does this</p>
  
  <pre><code> function currentfunction($id)
  { 
      $query = $this-&gt;db-&gt;get_where('mytable', array("id =" =&gt; $id));
  
      if($query-&gt;num_rows() &gt; 0){
          return $query-&gt;result_array();
      }else {
          return false;
      }
  }
  </code></pre>
  
  <p>The controller </p>
  
  <pre><code>$this-&gt;load-&gt;model('Display');
  $results = $this-&gt;Display-&gt;currentfunction($id);
  $this-&gt;load-&gt;view('current_items', array('currentitems' =&gt; $results));
  </code></pre>
  
  <p>The view</p>
  
  <pre><code>foreach($currentitems as $row){
                echo $row['name']
                ///....do more
                }
  </code></pre>
  
  <p>works just fine EXCEPT IF no rows are returned</p>
  
  <p>then</p>
  
  <pre><code>Message: Invalid argument supplied for foreach()...
  </code></pre>
  
  <p>How do I handle the if...else...scenario</p>
  
  <p>I tried <a href="https://stackoverflow.com/questions/3667715/counting-the-number-of-results-returned-by-a-database-query-in-codeigniter">this Q-A</a>, but doesn't work for me. PlsHlp.</p>