Table Name: ITEM
+-----+--------+----------+--------------------+--------------------------------------------+ | id | parent | category | heading | name | +-----+--------+----------+--------------------+--------------------------------------------+ | 228 | 0 | 0 | Website | | | 233 | 0 | 0 | Search Engine | | | 245 | 228 | 0 | Optional Features | | | 234 | 0 | 0 | Domain and Hosting | | | 232 | 0 | 0 | Design | | | 411 | 0 | 232 | | Logo Design | | 412 | 0 | 233 | | Search Engine Optimisation (SEO) - Monthly | | 413 | 0 | 233 | | Search Engine Marketing (SEM) | | 414 | 0 | 245 | | Blog | | 415 | 0 | 245 | | Newsletter | | 416 | 0 | 245 | | Favicon | | 410 | 0 | 228 | | Shopping Cart | | 409 | 0 | 228 | | Back End (CMS) | | 408 | 0 | 228 | | Front End | | 422 | 0 | 234 | | SSL Certificate | | 421 | 0 | 245 | | Payment Gateway | | 420 | 0 | 234 | | Dedicated IP | | 419 | 0 | 234 | | Hosting - Yearly | | 418 | 0 | 234 | | Domain Name | | 417 | 0 | 245 | | Multiple Languages | | 864 | 0 | 865 | | New One | +-----+--------+----------+--------------------+--------------------------------------------+
-I've created a menu which looks like this:
Website () Optional Features () Design () Search Engine () Domain and Hosting ()
-In the brackets, I would like to add the number of items per category INCLUDING child items
-So for example, 'Website' should 8 items (have 3 + 5 from 'Optional Features')
-Since the number of levels/parents are not limited, I need a recursive query to get this number.
-The tree is currently functioning properly and can be seen here: https://www.mekoowebdesign.com.au/cart/
THE QUESTION -How do I write a recursive MySQL query which will return the number of items in each menu INCLUDING the number of items in its children?