Use PHP to implement a multi-level tree menu .? Tree directory structure template program menu directory field description: menu_id menu item idmenu menu name menu_grade menu level 1 is the main menu 2 is the level 2 menu ........ // 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
Function my_menu ($ menu_content, $ I, $ menu_grade_temp, $ menu_superior_temp)
{
Global $ PHP_SELF;
$ Temp1 = $ menu_grade_temp + 1;
$ Menu_superior_temp_array = split ("/", $ menu_superior_temp );
For ($ t = 0; $ t <$ I; $ t ++)
{
$ Menu_array = split ("/", $ menu_content [$ t]);
If ($ menu_array [2] ==$ menu_grade_temp) & ($ menu_array [3] ==$ menu_superior_temp_array [$ menu_grade_temp-1])
{
For ($ p = 1; $ p <= $ menu_grade_temp; $ p ++) {echo "";}
$ Temp3 = $ menu_superior_temp_array;
$ Temp3 [$ menu_grade_temp] = $ menu_array [0];
$ Temp2 = implode ("/", $ temp3 );
If ($ menu_array [0] ==$ menu_superior_temp_array [$ temp1-1])
{
$ Temp5 = $ temp1-1;
$ Temp3 [$ menu_grade_temp] = "";
$ Temp6 = implode ("/", $ temp3 );
Echo "$ menu_array [1]
";
My_menu ($ menu_content, $ I, $ temp1, $ temp2 );
}
Else
{
$ Temp3 [$ menu_grade_temp + 1] = "";
$ Temp6 = implode ("/", $ temp3 );
Echo "$ menu_array [1]
";
}
}
}
}
// Connect to the MySql database
$ Db_host = "localhost ";
$ Db_user = "dkj ";
$ Db_password = "123 ";
$ Db_name = "test ";
Mysql_connect ($ db_host, $ db_user, $ db_password );
Mysql_select_db ($ db_name );
// 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 ');
*/
?>
Http://www.bkjia.com/PHPjc/316346.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/316346.htmlTechArticle? // Tree directory structure template program // menu Directory Library field description: // menu_id menu item id // menu name // menu_grade menu Level 1: Main menu 2: Level 2 menu ...........