如何按组菜单对数据进行排序?

问题描述 投票:0回答:1

如何按

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

我要显示内容菜单

Ex.

  • 测试6
  • -subtest6
  • --subtest6-2
  • ---子测试6-2-1
  • 测试7

如何查询?

php mysql mysqli hierarchical-data
1个回答
0
投票

如果你想有无限的子菜单,用PHP循环可能更容易。

制作2级菜单还是很容易的,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

按 pc.pc_group、pc.pc_sort、pc.pc_id 排序

或者您可以重新设计类别表以获得简单且无限的子菜单树:

pc_id
11
1122   -- kid of 11
112233 -- kid of 1122
55
66
6677   -- kid of 66
© www.soinside.com 2019 - 2024. All rights reserved.