How to make a dynamic tree structure menu

To make dynamic tree structure menu, We have to make to functions one is for “Parent Menu” and second for “Child Menu or Sub Child Menu”.

$query = “select * from categories where parentid=’0′”;
$result = mysql_query($query);
$list .= “<ul>”;
while($row = mysql_fetch_array($result))
{

$list .= “<li>$row[name]”;
$l = child($row[id]); $list .= $l;
$list .= “</li>”;
}
$list .= “</ul>”;

$list = str_replace(‘<ul></ul>’, ”, $list);
echo $list;

function child($parent) {
$query1 = “select * from categories where parentid=’$parent'”;
$result1 = mysql_query($query1);
$rc = mysql_fetch_row($query1);
$list .= “<ul>”;
while($row1 = mysql_fetch_array($result1))
{

$list .= “<li>$row1[name]”;
$l = child($row1[id]); $list .= $l;
$list .= “</li>”;
}
$list .= “</ul>”;
return $list;
}

To download complete script Click Here

Share This Post

Post Comment