title: How do I get the count of all the products in a category and its sub categories (and sub-sub categories)?
body: <p>The category table looks like somewhat as below:</p>
  
  <pre><code>id -- name -- parent_id
  1  -- Men    -- 0
  2  -- Women  -- 0
  3  -- Shirts -- 1
  4  -- Half-sleeve -- 3
  5  -- Full-sleeve -- 3
  </code></pre>
  
  <p>Relationship table:</p>
  
  <pre><code>Product_id -- Category Id
  1          -- 2
  2          -- 2
  3          -- 4 ....
  </code></pre>
  
  <p>I can retrieve the number of products in any one category and its immediate sub categories with ease with ease. But if there are more than 2 levels things get messy. </p>
  
  <p>So my question is How do I get the number of all of the products in Men and its sub categories. Or Shirts and its subcategories?</p>
  
  <p>Any ideas, Thanks.</p>
  
  <p>UPDATE: </p>
  
  <p>I know there is Nested Set Model but I am not in position to change the structure to that now.</p>