# Database Treemenu Help

**URL:** <https://forum.kirupa.com/t/database-treemenu-help/279362>\
**Category:** programming\
**Created:** [January 13, 2009, 11:11pm UTC](https://forum.kirupa.com/t/database-treemenu-help/279362 "2009-01-13T23:11:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![james182](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@james182](https://forum.kirupa.com/u/james182)\
**Post date:** [January 13, 2009, 11:11pm UTC](https://forum.kirupa.com/t/database-treemenu-help/279362/1 "2009-01-13T23:11:35Z")

</div>

I need to get this from pulling data from a directory to generating it from a Database.

**my Database: tbl\_tree\_menu**

## treeview\_id | treeview\_name | treeview\_desc | treeview\_parent\_id

```
    1 | root | folder | 0

```

* * *

```
   2 | 1. Parent | folder | 1

```

* * *

```
   3 | 2. Parent | folder | 1

```

* * *

```
   4 | 1. Child P1 | folder | 2

```

* * *

```
   5 | 2. Child P1 | folder | 2

```

* * *

```
   6 | My Doc PC1 | document | 4

```

* * *

```php
<?php
$_POST['dir'] = urldecode($_POST['dir']);
if( file_exists($root . $_POST['dir']) ) {
 $files = scandir($root . $_POST['dir']);
 natcasesort($files);
 if( count($files) > 2 ) { /* The 2 accounts for . and .. */
  echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">";
  // All dirs
  foreach( $files as $file ) {
   if( file_exists($root . $_POST['dir'] . $file) && $file != '.' && $file != '..' && is_dir($root . $_POST['dir'] . $file) ) {
    echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . htmlentities($_POST['dir'] . $file) . "/\">" . htmlentities($file) . "</a></li>";
   }
  }
  // All files
  foreach( $files as $file ) {
   if( file_exists($root . $_POST['dir'] . $file) && $file != '.' && $file != '..' && !is_dir($root . $_POST['dir'] . $file) ) {
    $ext = preg_replace('/^.*\./', '', $file);
    echo "<li class=\"file ext_$ext\"><a href=\"#\" id=\"1\" rel=\"" . htmlentities($_POST['dir'] . $file) . "\">" . htmlentities($file) . "</a></li>";
   }
  }
  echo "</ul>"; 
 }
}
?>

```
