Home  >  Article  >  Backend Development  >  Implementing multi-level tree menu with PHP_PHP tutorial

Implementing multi-level tree menu with PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:03:15815browse

//Tree directory structure template program
//Menu directory library field description:
//menu_id menu item id 1 is the main menu and 2 is the secondary menu.....
//menu_superior Previous menu id number

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& lt ;$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]))                                                      temp3=$menu_superior_temp_array;
$temp3[$menu_grade_temp]=$menu_array[0];
$temp2=implode("/",$temp3); menu_superior_temp_array[$temp1-1])                                                              lode("/",$temp3 ; my_menu($menu_content,$i,$temp1,$temp2);                                                                               >         $temp6=implode( "/",$temp3);
echo "$menu_array[1] }                                                              kj";
$db_password="123";
$db_name="test";
mysql_connect($db_host,$db_user,$db_password);
mysql_select_db($db_name);

//From Obtain 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;
}

//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
# 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', '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', '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.html

truehttp: //www.bkjia.com/PHPjc/316346.htmlTechArticle? //Tree directory structure template program //Menu directory field description: //menu_id menu item id / /menu Menu name//menu_grade Menu level 1 is the main menu and 2 is the secondary menu.....
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn