php+mysql+js implements tree menu code This is a php+mysql database that reads the content of the database and regenerates it into a tree model menu controlled by js
php tutorial+mysql tutorial+web page special effects to implement tree menu code
This is a php+mysql database tutorial that reads the contents of the database and regenerates the tree model menu controlled by js
*/
?>
Category tree
$globals["id"] =1; //The id number used to track the drop-down menu
$layer=1; //The level used to track the current menu
//Connect to database
$con=mysql_connect("localhost","root","123456");
mysql_select_db("demo");//Extract the first-level menu
$sql="select * from think_news where `f_id`=0";
$result=mysql_query($sql,$con);
//If the first-level menu exists, display the start menu
if(mysql_num_rows($result)>0) showtreemenu($con,$result,$id);
function showtreemenu($con,$result,$layer)
{
//Get the number of menu items that need to be displayed
$numrows=mysql_num_rows($result);
//Start to display the menu, each submenu is represented by a table
echo "";
";
for($rows=0;$rows<$numrows;$rows++)
{
//Import the contents of the current menu item into the array
$menu=mysql_fetch_array($result);
//Extract the submenu record set of menu items
$sql="select * from think_news where f_id=$menu[id]";
$result_sub=mysql_query($sql,$con);
echo ""; ";
//If the menu item has a submenu, add the javascript onclick statement
If(mysql_num_rows($result_sub)>0)
{
echo "";
echo "";
}
else
{
echo "";
echo "";
}
//If the menu item has no submenu, only the menu name is displayed
echo $menu["title"];
echo "
//If the menu item has a submenu, display the submenu
If(mysql_num_rows($result_sub)>0)
{
//Specify the id and style of the submenu to correspond to the onclick statement
echo " ";
}
//Submenu processing is completed, return to the previous level of recursion, and reduce the series by 1
$layer--;
}
echo "
}