Home > database >  Tree structure data query returns?
Tree structure data query returns?

Time:09-26

A menu list, need according to user permissions for menus and menu of the father, user rights reserved the menu in the table id, id no save the parent menu, each menu item has a field recorded the id of the parent menu string, the format is: the primary parent id, secondary id, tertiary parent id...

How do I once found the user menu and menu of all parent menu?


CodePudding user response:

It is better for table structure and data can be analyzed,

CodePudding user response:

Table structure, the test data, the expected results, all the way, others guess not to come out,

CodePudding user response:

Sorry, description of some simple, supplement, use mysql:
Such as data structure is as follows:
The CREATE TABLE ` t_menu ` (
` id ` int (11), NOT NULL COMMENT 'menu ids,
` name ` varchar (30) NOT NULL,
` parent_id ` varchar (50), NOT NULL COMMENT 'parent menu iD sequence (level 1 menu ids. The secondary menu ids. Submenus iD... ) '
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
- Records of t_menu
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
INSERT INTO ` t_menu ` VALUES (' 1 ', '1' level menu, ");
INSERT INTO ` t_menu ` VALUES (' 2 ', the secondary menu 1 ', '1');
INSERT INTO ` t_menu ` VALUES (' 3 ', 'submenus 1', '1.2');
INSERT INTO ` t_menu ` VALUES (' 4 ', '2' 3 menu, '1.2');
INSERT INTO ` t_menu ` VALUES (' 5 ', 'level 1', '1');

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the corresponding menu below:
Level 1 menu 1
| -- -- -- -- -- -- -- -- -- -- the secondary menu 1
| -- -- -- -- -- -- -- -- -- -- submenus 1
| -- -- -- -- -- -- -- -- -- -- 3 menu 2
| -- -- -- -- -- -- -- -- -- -- -- -- -- -- 4 menu 1

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
When user menu only retained [submenus 1], [3 menu 2], [1] four menu ids,
Query time to restore the tree above menu, which is to find out [1] the secondary menu and [1] level menu to





CodePudding user response:

The original poster can inquire the select... Connect by the statement
  • Related