VAB Posted August 26, 2020 Share Posted August 26, 2020 (edited) 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 Quote Link to comment https://forums.phpfreaks.com/topic/311389-treeview-in-php/ Share on other sites More sharing options...
requinix Posted August 26, 2020 Share Posted August 26, 2020 5 minutes ago, VAB said: when i click on the node, the link ;doesn't work Do you have any suggestions for how we might be able to find out what "doesn't work" could possibly mean? Quote Link to comment https://forums.phpfreaks.com/topic/311389-treeview-in-php/#findComment-1580971 Share on other sites More sharing options...
VAB Posted August 26, 2020 Author Share Posted August 26, 2020 when i Click on node of the tree , the new page don't open. each node is linked with <a> tag as u may have noticed in the code as well. Quote Link to comment https://forums.phpfreaks.com/topic/311389-treeview-in-php/#findComment-1580972 Share on other sites More sharing options...
Phi11W Posted August 26, 2020 Share Posted August 26, 2020 What does the generated HTML look like (Use the "View Source" tool in your browser). Remember that your PHP is effectively just building a String that gets sent to the browser for it to make sense of. Copy the link URL out of the browser and make sure that that it works on its own. It may simply be that $row['linkpage'] isn't a valid URL. Regards, Phill W. Quote Link to comment https://forums.phpfreaks.com/topic/311389-treeview-in-php/#findComment-1580975 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.