Mysql row counting

I have a table called pages. In this table are columns called ‘is_cat’ and ‘catid’.

‘cat_id’ is a column that gives each page a category id.
‘is_cat’ tells whether the page is a regular page or subpage by giving a ‘0’ or ‘1’.

What I am wanting to do is loop through each page and grab how many subpages there are for each category. Then I want it to produce a certain variable for each time there is a subpage.

So for instance, the category ‘Fire Forensics’ might have 5 pages. 2 of them are subcategories. So I want the code to tell me that I have 2 subcategories for that category and produce a variable 2 times.

I hope I explained this well enough. Can anyone help me?