title: Codeigniter - in view while foreach-ing get row count from another table by id
body: <p>I have Categories Controller - index</p>
  
  <pre><code>public function index()
      {
  
          $query = $this-&gt;db-&gt;query("SELECT * FROM categories ORDER BY priority");
          $this-&gt;_viewdata['categories'] = $query-&gt;result();
          //-- I will use model for mysql queries!
  
          $this-&gt;load-&gt;view('admin/categories', $this-&gt;_viewdata);
      }
  </code></pre>
  
  <p>In view Im printing results using foreach:</p>
  
  <pre><code>&lt;?php
      foreach ($categories as $category) {
  ?&gt;
         Name: &lt;?=$category-&gt;name;?&gt; // and etc...
         Subcategories: // &lt;- I want to get subcats count for every category by its id (where catid='$category-&gt;id') like this
      &lt;?php
      }
      ?&gt;
  </code></pre>
  
  <p>I have another table called "subcategories" and I have "catid" column inside it. And I want to get every Subcategories count by Category and display it inside view. How can I do this?</p>