表名: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 | +-----+--------+----------+--------------------+--------------------------------------------+
- 我已经创建了一个如下所示的菜单:
Website () Optional Features () Design () Search Engine () Domain and Hosting ()
- 在括号中,我想添加每个类别的项目数量包括子项目
- 例如,'网站'应该有8个项目(有3 + 5来自'可选功能')
- 由于级别/父级的数量不受限制,我需要一个递归查询来获取此数字。
- 树目前正常运行,可在此处查看:https://www.mekoowebdesign.com.au/cart/
问题 - 如何编写递归MySQL查询,返回每个菜单中的项目数,包括其子项中的项目数?