如何按groupmenu对数据进行排序?

How to sort data by groupmenu?

mysql

SELECT pc.pc_id, pc.pc_icon, pc.pc_parent, pcd.pcd_name, pcd.pcd_id 
FROM product_category pc 
LEFT JOIN product_category_detail pcd ON pcd.pc_id=pc.pc_id 
ORDER BY pc.pc_group, pc.pc_sort, pc.pc_id

enter image description here

I want to show content menu

Ex.

  • test6
  • -subtest6
  • --subtest6-2
  • ---subtest6-2-1
  • test7

How i can query it? Thank you

If you want to have unlimited sub-menu, it might be easier to use PHP to loop.

It's still easy to produce 2 levels of menu, eg

SELECT a.id,
FROM 
SELECT pc.pc_id, pc.pc_icon, pc.pc_parent, pcd.pcd_id,
concat(if (pc.pc_parent = 0, '', '- '), pcd.pcd_name) AS pcd_name
FROM product_category AS pc
LEFT JOIN product_category_detail AS pcd ON pcd.pc_id = pc.pc_id

ORDER BY pc.pc_group, pc.pc_sort, pc.pc_id

OR you might redesign the category table to have an easy and unlimited sub-menu trees:

pc_id
11
1122   -- kid of 11
112233 -- kid of 1122
55
66
6677   -- kid of 66