PHP + JS unlimited scalable menu details (easy to understand) _ php instance

Source: Internet
Author: User
PHP + JS unlimited scalable menu details (easy to understand) released a few days of basic things, today is a little difficult, the essence of Category Management, which is generally used in the background of the CMS system, is the unlimited classification menu. This may be difficult for beginners, but I will give it a closer look after hearing it today, I believe that this will be done in the future. How can this problem be achieved? Let's make a database first:
--
-- Table structure 'cr _ columninfo'
--

The Code is as follows:

Create table 'cr _ columninfo '(
'Columnid' int (4) not null auto_increment,
'Columnfatherid' int (4) not null default '0 ',
'Columnname' varchar (100) not null default '',
'Columnadder' varchar (50) not null default '',
'Columninputdate' date not null default '2017-00-00 ',
Primary key ('columnid ')
) ENGINE = MyISAM AUTO_INCREMENT = 15 default charset = utf8 AUTO_INCREMENT = 15;
-- Export the table data 'cr _ columninfo'
--
Insert into 'cr _ columninfo '('columnid', 'columnfatherid', 'columnname', 'columnadder', 'columninputdate') VALUES (1, 0, 'audio and video start ', 'leeihui', '2017-09-28 '),
(2, 0, 'campus style', 'leehui1983 ', '2017-09-28 '),
(3, 1, 'Hong Kong and Taiwan Stars', 'leeihui', '2017-09-28 '),
(4, 0, 'landscape image', 'leehui1983 ', '2017-09-29 '),
(5, 4, 'vast sea ', 'leehui1983', '2017-09-29 '),
(6, 5, 'fuzhou hai', 'leehui1983 ', '2017-09-29 '),
(7, 2, 'Graduation image', 'leeihui', '2017-09-29 '),
(9, 0, 'Sports start', 'leehui1983 ', '2017-10-02 '),
(10, 0, 'exquisite wallpaper ', 'leehui1983', '2017-10-02 '),
(11, 0, 'city scenery ', 'leehui1983', '2017-10-02 '),
(12, 0, 'cartoon animate', 'leei1983 ', '2017-10-02 '),
(13, 0, 'game', 'leei1983 ', '2017-10-02 '),
(14, 0, 'author album ', 'leehui1983', '2017-10-02 ');


These are test data. The basic principle is to establish data fields according to the tree structure. The core is that the column has its own ID number and the ID number of its parent column. Based on these two relationships, the tree structure is established, parent ID = 0 in the top-level topic. This article describes the program execution principle. This program uses the most common recursive algorithm to traverse sub-menus. First, first, all top-level menus are displayed in a big table. No top-level menus are displayed in one row. Then, all sub-menus are recursively listed. The sub-menus are located in the next row of the top-level menu, the row display attribute is not displayed. The row ID dynamically generated by the program is combined with the display and hiding of JS control lines, which is similar to the Scalable Effect of Microsoft menu, at the end of the article, there is a graph to help you understand. This is to copy the HTML of the generated page into DW to demonstrate the final result of the program.
There is no obscure syntax to look at the code. Please read it with comments and be interested in extending the code.
The PHP code is as follows:

The Code is as follows:




CATEGORY directory tree

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.