Home > Article > Backend Development > PHP unlimited classification (with database) (1/2)_PHP tutorial
This is a PHP infinite-level classification code written using recursion. It is a tree-type infinite-level classification example. The infinity is achieved by using recursion. There are also more advanced writing methods, binary trees to achieve infinite classification. .
php tutorial unlimited classification (with database tutorial)
/*
This is a PHP infinite-level classification code written using recursion. It is a tree-type infinite-level classification example. The infinity is achieved by using recursion. There are also more advanced writing methods, binary trees to achieve infinite classification.
*/
?>
电视树状目录
$globals["id"] =1;
$jibie=1;
$sql="select * from tvmenu where bid=0";
$result=mysql教程_query($sql,$conn);
if(mysql_num_rows($result)>0)
treemenu($conn,$result,$jibie,$id);
function treemenu($conn,$result,$jibie) //进入函数循环
{
$numrows=mysql_num_rows($result);
echo "";
";
for($rows=0;$rows<$numrows;$rows++)
{
$menu=mysql_fetch_array($result);
$sql="select * from tvmenu where bid=$menu[id]";
$result_sub=mysql_query($sql,$conn);
echo ""; ";
//如果该菜单项目有子菜单,则添加javascript onclick语句
if(mysql_num_rows($result_sub)>0)
{
echo "";
echo "";
}
else
{
echo "";
echo "";
}
if($menu[url]!="")
echo "$menu[name] ";
else
echo "$menu[name] 添加 编辑 删除";
echo "
if(mysql_num_rows($result_sub)>0)
{
echo " ";
}
//显示下一菜单
}
echo "
}
?>
1 2