Recursive directory tree, how to set up UL LI
This post was last edited by xingguangyingying on 2013-04-15 08:18:54
Function nav ($parent) {
$sql = mysql_query ("Select * from menu where parent = ' $parent '");
while ($row = Mysql_fetch_array ($sql)) {
Echo '
'. $row [' name ']. ';
Nav ($row [' id ']);
Echo '';
}
}
How to set the sub-class UL output it?
Like this
------Solution--------------------
You query the side output, so you can not know whether the current node has child nodes (because it has not been read)
So you need to read the query results to the array http://bbs.csdn.net/topics/390364669
And then recursively output
You can also cache what you want to output with a variable, and then output it when the recursion ends
Function nav ($parent) {
$res = ";
$sql = mysql_query ("Select * from menu where parent = ' $parent '");
while ($row = Mysql_fetch_array ($sql)) {
$res. = '
'. $row [' name ']. ';
$t = Nav ($row [' id ']);
if (! empty ($t)) $res. = "
";
$res. = '';
}
return $res;
}
When called
Echo nav ($id);
I have been dynamically loaded with Ajax, so there is no recursion.
At least not for you at the moment.