Jump to content

Tree parent child menu


dhimo

Recommended Posts

It would be very nice to have the menu expanded to get to the child menus. Some javascript would be great. I can fix that myself. So how can i only show main parents and then go deeper show sub parents and then children? Would be nice if only children are linked to the show page. If u could help me to put children in divs that would be great

function show_categories($parent = 0, $depth = 0){  $retval = "<br />";    $padding = $depth * 10;  $result = mysql_query("SELECT * FROM tbl_category WHERE cat_parent_id='$parent'");  while ($row = mysql_fetch_assoc($result))  {	extract($row);	$retval .= "<div style=\"padding-left: {$padding}px;\"><a href=\"?$cat_id\">".$cat_name."</a></div>";	$retval .= show_categories($cat_id, $depth + 1);  }  return $retval;}

Link to comment
Share on other sites

In that function, the $retval variable gets appended to twice inside the while loop. The first time it gets a div that holds the category name, and the second time it gets the result of the function being ran on that category, which is to say all of the category's children. If you wrap the recursive function call inside a div tag, so that the div starts before the function call and ends after it, then the div will contain all of the subcategories. Then you can use CSS and javascript to have a link on the parent category name that shows or hides the child div.Also, when replying it's probably better to keep it all in one thread, in case there is an earlier reply to reference.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...