Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

PHP Treeview in PHP

VAB

New Coder
I wrote the following code in php but when i click on the node, the link ;doesn't work

See Attached file for your reference.
When I click on the itemMaster, the page does not open


<?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 ?>


Pls revert.
 

Attachments

  • prob_php.webp
    prob_php.webp
    5.4 KB · Views: 7
Last edited:
Hi there

I think you are having problems with generated HTML. To solve it, first create a HTML instance of your page by hand, with all the elements you'd have at the end. Then, when it all works out, use php to generate actual HTML using elements you tested out.
 
I think you need to make sure you wrap the $menu code with <ul><?php echo $menu ?></ul> so the parent list is recognized as a proper list... Perhaps I am mistaken. Please explain your problem with more details about what exactly you expect to happen, and if possible please provide us with the outputted code that your script produces.
 
Back
Top Bottom