Implementation of multilevel tree menu with PHP

Source: Internet
Author: User

Tree-type directory structure template program
Menu Directory Gallery Field Description:
MENU_ID menu item ID
Menu Name
Menu_grade Menu Level 1 Main Menu 2 is level two menu ...
Menu_superior Top level Menu ID number

function My_menu ($menu _content, $i, $menu _grade_temp, $menu _superior_temp)
{
Global $PHP _self;
$temp 1= $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 "";}
$temp 3= $menu _superior_temp_array;
$temp 3[$menu _grade_temp]= $menu _array[0];
$temp 2=implode ("/", $temp 3);
if ($menu _array[0]== $menu _superior_temp_array[$temp 1-1])
{
$temp 5= $temp 1-1;
$temp 3[$menu _grade_temp]= "";
$temp 6=implode ("/", $temp 3);
echo "$menu _array[1]
";
My_menu ($menu _content, $i, $temp 1, $temp 2);
}
Else
{
$temp 3[$menu _grade_temp 1]= "";
$temp 6=implode ("/", $temp 3);
echo "$menu _array[1]
";
}
}
}
}
Connecting 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);

Get data from the database
$query _string= "SELECT * from Menu order by Menu_grade";
$db _data=mysql_query ($query _string);

The first time the initialization is performed
if ($menu _grade_temp== "")

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.