Web Analytics Made Easy -
StatCounter How to generate tree structure - CodingForum

Announcement

Collapse
No announcement yet.

How to generate tree structure

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to generate tree structure

    Hi,

    I want to generate tree menu based on hierarchy. as below.

    Building
    Floors
    Locations

    The following script fetches the building names.How can i modify this to Fetch the floors and locations associated to it.

    When i click on buildings it should expand and display floors and if the floors has locations it should expand to locations.

    Please help


    PHP Code:
    <?php 
    /* Begin code: */
    /* My database connection include file */
    $db_host "test"
    $db_user "test"
    $db_pass "test"
    $db_name "test"

    $connection mysql_connect($db_host$db_user$db_pass) or die ("Unable to connect to DB"); 
    mysql_select_db($db_name$connection); ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html>

    <head>
        <title>Tree Menu</title>

        <link rel="StyleSheet" href="dtree.css" type="text/css" />
        <script type="text/javascript" src="dtree.js"></script>

    </head>

    <body>
    <div class="dtree">

        <p><a href="javascript: d.openAll();">open all</a> | <a href="javascript: d.closeAll();">close all</a></p>

    <script type="text/javascript">

    d = new dTree('d');
    d.add(0,-1,'Your Documents');
    <?php
    /* Variables from my database include file */

    $query "SELECT buildingId,name FROM buildings ORDER BY buildingId";
    $result mysql_query($query$connection) or die ("Fail Query");
    while (
    $row mysql_fetch_array($result)) {
    extract($row);
    echo(
    "
            d.add('
    $buildingId','0','$name','$title','test.html');
            
        "
    );
    }

    ?>
    document.write(d);

    </script>
    </div>
    </body>
    </html>
    <?php mysql_free_result($result); 
    /* End Code */
    ?>
Working...
X