title: get all items of category and its child
body: <p><strong>I'm about to give 100 bounty points for answer to this question</strong></p>
  
  <p>So I have very difficult question about recursions - how to get all items count of category and all childs that contains that parent and more deeper until the end?</p>
  
  <p>I have table:</p>
  
  <pre><code>+----+---------------+-----------------+
  | id | category name | category_parent |
  +----+---------------+-----------------+
  | 1  | cars          |        0        |
  +----+---------------+-----------------+
  | 2  | real estate   |        0        |
  +----+---------------+-----------------+
  | 3  | clothes       |        0        |
  +----+---------------+-----------------+
  | 4  | bmw           |        1        |
  +----+---------------+-----------------+
  | 5  | audi          |        1        |
  +----+---------------+-----------------+
  | 6  | 100           |        5        |
  +----+---------------+-----------------+
  | 7  | 80            |        5        |
  +----+---------------+-----------------+
  | 8  | A4            |        5        |
  +----+---------------+-----------------+
  | 9  | QUATRO        |        8        |
  +----+---------------+-----------------+
  | 10 | TDI           |        8        |
  +----+---------------+-----------------+
  | 11 | Black         |        9        |
  +----+---------------+-----------------+
  | 12 | White         |        9        |
  +----+---------------+-----------------+
  | 13 | 2 doors       |        11       |
  +----+---------------+-----------------+
  | 14 | 5 doors       |        11       |
  +----+---------------+-----------------+
  </code></pre>
  
  <p>and my products table look like this:</p>
  
  <pre><code>+----+---------------+-----------------+
  | id | category_id   | name            |
  +----+---------------+-----------------+
  </code></pre>
  
  <p>and for example I want to count all items that are in <code>cars</code> category. So basically I should pass this category id <code>(1)</code> and somehow make a recursion to count all items. But I have no idea how to deal with it, becouse childs of that category could be unlimited.</p>
  
  <p>So when I want to know all items of that parent count, I should make something like this:</p>
  
  <pre><code>1++:
    4++
    5++:
      6++
      7++
      8++:
        9++:
          11++:
             13++
             14++
          12++
        10++
  </code></pre>
  
  <p>I hope you will understand what I need and give me any suggestion that could help me.</p>
  
  <p>also, this is the begining I have made so far - I could implement it but in the future I will stuck in recursion... so its worth nothing.</p>
  
  <pre><code>public function get_category_tree_id_list($cat_id, $list_array = FALSE)
  {
      if ( !$list_array ){
          $items = $this-&gt;system-&gt;_getCustomTableData('categories', array(array('category_parent' =&gt; $cat_id)), 'id DESC');
          $this-&gt;__tmp['id_list'] = [];
          foreach ( $items as $key =&gt; $value ) {
              $this-&gt;__tmp['id_list'][] = $value['id'];
          }
      }        
  }
  </code></pre>