Implement multi-level tree menu with PHP // Tree directory structure template program
// Menu directory field description:
// Menu_id menu Project id
// Menu name
// Menu_grade Level 1: Main Menu 2: Level 2 ........
// Menu_superior top-level menu id
// Obtain data from the database
$ Query_string = "select * from menu order by menu_grade ";
$ Db_data = mysql_query ($ query_string );
// Perform initialization for the first time
If ($ menu_grade_temp = "")
{
$ Menu_superior_temp = 0;
}
// Read all information into the array and count the number of arrays
$ I = 0;
While (list ($ menu_id, $ menu, $ menu_grade, $ menu_superior) = mysql_fetch_row ($ db_data ))
{
$ Menu_content [$ I] = $ menu_id. "/". $ menu. "/". $ menu_grade. "/". $ menu_superior;
$ I ++;
}
My_menu ($ menu_content, $ I, 1, $ menu_superior_temp );
/* Attach the database structure and simulation data
# PhpMyAdmin MySQL-Dump
#
# HOST: localhost database: test
#--------------------------------------------------------
#
# Data table structure 'menu'
#
Create table menu (
Menu_id int (11) not null auto_increment,
Menu varchar (20) not null,
Menu_grade int (11) not null,
Menu_superior int (11) not null,
UNIQUE menu_id (menu_id)
);
#
# Export the following database content 'menu'
#
Insert into menu VALUES ('1', 'computer ', '1', '0 ');
Insert into menu VALUES ('2', 'programmatically ', '2', '1 ');
Insert into menu VALUES ('3', 'network', '2', '1 ');
Insert into menu VALUES ('4', 'php and mysql', '3', '2 ');
Insert into menu VALUES ('5', 'c language ', '3', '2 ');
Insert into menu VALUES ('6', 'webpage maker ', '3', '3 ');
Insert into menu VALUES ('7', 'tcp, ipprotocol ', '3', '3 ');
Insert into menu VALUES ('8', 'mat', '1', '0 ');
Insert into menu VALUES ('9', 'advanced Mathematics ', '2', '8 ');
Insert into menu VALUES ('10', 'linear algebra ', '3', '9 ');
Insert into menu VALUES ('11', 'Discrete mat', '3', '9 ');
Insert into menu VALUES ('12', 'Elementary mat', '2', '8 ');
Insert into menu VALUES ('13', 'literary ', '1', '0 ');
Insert into menu VALUES ('14', 'Chinese literature ', '2', '13 ');
Insert into menu VALUES ('15', 'php', '4', '4 ');
Insert into menu VALUES ('16', 'mysql', '4', '4 ');
*/
?>
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.