I'm trying to create a treeview which is mostly populted by a database. I have two code snippets which on their own work fine but when I place them together it won't seem to work no matter what I try.

Main Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-GB">

<head>   
    <!--[if gte IE 9 ]><link rel="stylesheet" type="text/css" href="_styles.css" media="screen"><![endif]-->
    <!--[if !IE]>--><link rel="stylesheet" type="text/css" href="_styles.css" media="screen"><!--<![endif]-->

    <title>Pure CSS collapsible tree menu</title>

</head>
<body>

    <ol class="tree">
        <li>
            <label for="folder3">Overdue</label> <input type="checkbox" id="folder3" /> 
            <ol>
                <li>
                    <label for="subfolder1">Training and Competence</label> <input type="checkbox" id="subfolder1" /> 
                    <ol>
                        <li class="file"><a href="">Subfile 1</a></li>
                        <li class="file"><a href="">Subfile 2</a></li>
                        <li class="file"><a href="">Subfile 3</a></li>
                        <li class="file"><a href="">Subfile 4</a></li>
                        <li class="file"><a href="">Subfile 5</a></li>
                        <li class="file"><a href="">Subfile 6</a></li>
                    </ol>
                </li>
            </ol>
        </li>
    </ol>

</body>
</html>

(I can provide the stylesheet if it is required too)

and then the database query:

<?php
    mysql_connect('localhost', 'root');
    mysql_select_db('test');

    $qry="SELECT * FROM treeview WHERE catagory LIKE 'Training%'";
    $result=mysql_query($qry);

    while($row = mysql_fetch_assoc($result)) 
    {
        echo "<li class='file'>";
        echo $row['name']; 
        echo "</li>";
    }
    mysql_free_result($result);
    mysql_close()
?>

This is being put in place of:

<li class="file"><a href="">Subfile 1</a></li>
<li class="file"><a href="">Subfile 2</a></li>
<li class="file"><a href="">Subfile 3</a></li>
<li class="file"><a href="">Subfile 4</a></li>
<li class="file"><a href="">Subfile 5</a></li>
<li class="file"><a href="">Subfile 6</a></li>

but when inserted it just outputs some of my query after echo "<li class='file'> so any insight would be appreciated! :)

Recommended Answers

All 3 Replies

it just outputs some of my query

Can you show what the output is ? Is it perhaps a query error, because catagory is misspelled ?

Sorry that's just something I didn't notice but it's spelt that way in the DB too.

"; echo $row['name']; echo ""; } mysql_free_result($result); mysql_close() ?>

is what i get where it normally displays the files

You're also missing a semi colon after mysql_close();

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.