PHP - Treeview In Php
I wrote the following code in php but when i click on the node, the link ;doesn't work <?php function get_menu_tree($parent_id) { global $conn; $menu = ""; //$sqlquery = " SELECT linkpage,moduleid,menuid,menuname,parentid,menudisplay FROM admnmenumaster where menudisplay='Y' and parentid='" .$parent_id . "' "; $sqlquery = " SELECT linkpage,moduleid,menuid,menuname,parentid,menudisplay FROM admnmenumaster where menudisplay='Y' and parentid='" .$parent_id . "' "; $result=sqlsrv_query($conn,$sqlquery); while($row = sqlsrv_fetch_array($result,SQLSRV_FETCH_ASSOC)) { $menu .="<li class=treeview><a href='".$row['linkpage']."'>".$row['menuname']."</a>"; $menu .= "<ul class=treeview-menu>".get_menu_tree($row['menuid'])."</ul>"; //call recursively $menu .= "</li>"; //echo "HELLO<a href=$row[linkpage]>$row[menuname]</a>"; } return $menu; } ?> <?php echo get_menu_tree(0); //start from root menus having parent id 0 ?> Edited August 26, 2020 by requinix please use the Code <> button when posting code Similar TutorialsAll I am not the best at PHP and have been trying to work out how to make a treeview from an array. I managed to get as afar as populating my array as i would like and I can get those values back but now im really stuck What id love to be able to do is use my area field as the parent and my title field as the child and have a counter on the parent with no of child nodes. If someone can help me out with that bit id be really greatful, as I ve already sorted my javascript etc this is my last problem and its driving me nuts Many Thanks for looking and i really do appreciate any help Gibbo <?php $row = 0; $myarray = array(); foreach ($view->result as $result) { $arg = $view->render_field('field_decision_type_value', $row); $arg2 = $view->render_field('title', $row); $myarray[$row]["area"]=$arg; $myarray[$row]["title"]=$arg2; $row++; } asort($myarray); $last = count($myarray) - 1; $rowcount=0; while ($rowcount <= $last) { print $myarray[$rowcount]["area"]; print $myarray[$rowcount]["title"].'|<br />'; $rowcount++; } ?> |