I have two table. Tables name of categories and items. I want to list category with item count.
categories table:
id | parent | catname | catpath
1 0 A 1
2 0 B 2
3 1 A1 1,3
4 3 A11 1,3,4
5 2 B1 2,5
6 0 C 6
....
items table:
id | catid | title
1 1 title1
2 1 title2
3 3 title3
4 4 title4
5 4 title5
6 3 title6
7 5 title7
And I want print categories like this: print catname (itemcount = own item count + sub category's item count)
A (4) /*<- sub category's item count + own item count*/
A1 (1)
A11 (2)
B (1)
B1 (1)
UPDATE: SQLFIDDLE