-
-
- //Tree directory structure template program
- //Menu directory library field description:
- //menu_id menu item id
- //menu menu name
- //menu_grade menu level 1 is the main menu 2 is the secondary menu...
- //menu_superior The id number of the previous menu
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 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);
//Get data from the database
- $query_string="select * from menu order by menu_grade";
- $db_data=mysql_query($query_string);
//First execution of initialization
- if ($menu_grade_temp=="")
- {
- $menu_superior_temp=0;
- } p>
//Read all the 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);
/* Attached database structure and simulation data
- # 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)
- );
- < ;p># Export the following database content 'menu'
- INSERT INTO menu VALUES( '1', 'Computer', '1', '0');
- INSERT INTO menu VALUES( '2', 'Programming', ' 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', 'Web page production', '3', ' 3');
- INSERT INTO menu VALUES( '7', 'TCP, IP protocol', '3', '3');
- INSERT INTO menu VALUES( '8', 'Math', '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 Mathematics', '3', '9');
- INSERT INTO menu VALUES( '12', 'Elementary Mathematics', '2', '8');
- INSERT INTO menu VALUES( '13', 'Literature', '1', '0');
- INSERT INTO menu VALUES( '14', 'Programmer's Home', '2', '13');
- INSERT INTO menu VALUES( '15', 'php', '4', '4');
- INSERT INTO menu VALUES( '16', 'mysql', '4', '4');
- */
- ?> ;
-
Copy code
|