0

我正在使用菜单模块并在检索有关订单的菜单时遇到问题。

请检查小提琴以供参考。

在数据库中:PARENTID 表示它是否是父代。如果 PARENTID=0,则为父菜单,否则为子菜单。

PARENTLEVEL - 是级别 1,2,3,4,5,6..

当我运行查询时,我可以按顺序获取菜单:

SELECT * FROM categoryWHERE publish='1' and parentid='0' 按menuorderASC排序

但是当我想订购子菜单时,我无法订购它们:

SELECT * FROM category c inner join category b on c.parentid = b.parentid where c.publish='1' and c.parentid!='0'

我试过了:

SELECT * FROM category p LEFT JOIN category c ON c.parentid=p.parentid WHERE p.publish=1 order by p.PARENTID,c.MENUORDER ;

我正在尝试的是:

我想要这样的结果:

    1.Home
    2.Settings
          Set Period
          User Type
          Roles
          Region
   .....etc

所以,我可以得到菜单顺序。有人可以帮我订购主菜单下的菜单/子菜单吗?

提前致谢!!

4

1 回答 1

0

好的,这里是编辑后的版本

SELECT p.menuname pmen,c.menuname cmen,
 COALESCE(c.menutype,p.menutype) menutype,
 COALESCE(c.link,p.link) link,
 COALESCE(c.accessgroup,p.accessgroup) accessgroup
FROM category p 
LEFT JOIN category c ON  c.parentid=p.id AND c.publish=1 
WHERE p.publish=1 and p.parentid='0'  
ORDER BY p.menuorder,c.menuorder

结果:

|            PMEN |                    CMEN | MENUTYPE |     LINK | ACCESSGROUP |
---------------------------------------------------------------------------------
|            Home |                  (null) | leftmenu | home.php |           1 |
|        Settings |              Set Period | leftmenu | home.php |           1 |
|        Settings |               User Type | leftmenu | home.php |           1 |
|        Settings |                   Roles | leftmenu | home.php |           1 |
|        Settings |                  Region | leftmenu | home.php |           1 |
|        Settings |                District | leftmenu | home.php |           1 |
|        Settings |                   State | leftmenu | home.php |           1 |
|        Settings |                    City | leftmenu | home.php |           1 |
|  Master Screens |            Product Type | leftmenu | home.php |           1 |
|  Master Screens |      Beneficiary Master | leftmenu | home.php |           1 |
|  Master Screens |        Component Master | leftmenu | home.php |           1 |
|  Master Screens |           Sub-Component | leftmenu | home.php |           1 |
|  Master Screens |              LOT Master | leftmenu | home.php |           1 |
|  Master Screens |           Tender Master | leftmenu | home.php |           1 |
|  Master Screens |         PDI Task Master | leftmenu | home.php |           1 |
| User Management |                    User | leftmenu | home.php |           1 |
| User Management |                    RBAC | leftmenu | home.php |           1 |
| TPI Task Master |                  (null) | leftmenu | home.php |           1 |
|    Transaction  |              Work Order | leftmenu | home.php |           1 |
|    Transaction  |                  Vendor | leftmenu | home.php |           1 |
|    Transaction  |          PDI Inspection | leftmenu | home.php |           1 |
|    Transaction  |          TPI Inspection | leftmenu | home.php |           1 |
|    Transaction  |           DE Inspection | leftmenu | home.php |           1 |
|    Transaction  |           RM Inspection | leftmenu | home.php |           1 |
|    Transaction  | Install & Commissioning | leftmenu | home.php |           1 |
|    Transaction  |         Re-Installation | leftmenu | home.php |           1 |
|    Transaction  |          Bank Guarantee | leftmenu | home.php |           1 |
|    Transaction  |        Initiate Invoice | leftmenu | home.php |           1 |
|        Accounts |        Invoice Approval | leftmenu | home.php |           1 |
|         Reports |                  (null) | leftmenu | home.php |           1 |
于 2013-08-09T10:19:38.900 回答