10-20-2012, 02:47 AM
|
#1 (permalink)
|
|
The Visitor
Join Date: Oct 2012
Posts: 2
Thanks: 0
|
recursive function with collapsible menu
Hey Guys.
Ma' brain is stuck.
I'm currently working on customizing a menu. Got the following code, but wan't the list
to be collapsible without using any Javascript/Jquery, only pure PHP.
Do you guys have any idea how to do that?
PHP Code:
function display_children($parent, $level) {
$result = mysql_query("SELECT a.id, a.label, a.link, Deriv1.Count FROM `menu` a LEFT OUTER JOIN (SELECT parent, COUNT(*) AS Count FROM `menu` GROUP BY parent) Deriv1 ON a.id = Deriv1.parent WHERE a.parent=" . $parent);
echo "<ul>";
while ($row = mysql_fetch_assoc($result)) {
if ($row['Count'] > 0) {
echo "<li><a href='" . $row['link'] . "'>" . $row['label'] . "</a>";
display_children($row['id'], $level + 1);
echo "</li>";
} elseif ($row['Count']==0) {
echo "<li><a href='" . $row['link'] . "'>" . $row['label'] . "</a></li>";
} else;
}
echo "</ul>";
}
display_children(0, 1);
All help will be appreciated!
//Simon
|
|
|
|