Hi here are a litle recursive script that builds a tree like:
name
-name
--name
---name
-name
--name
-name
--name
---name
... and so on.
It takes data from a db structure like this
id int(9) auto_increment ... uniqe id
name char(255) ... name to be printed
_parent int(9) ... holds the parent id (id)
<?
$link = mysql_connect("localhost", "", "");
mysql_select_db("test");
?>
<?
function buildTree($id = 0, $cnt = 1) {
$query = "SELECT * FROM names WHERE _parent = ".$id."";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo str_repeat("*",$cnt);
echo $row['name']."<br>";
buildTree($row['id'], $cnt + 1);
}
}
?>
<?
buildTree();
?>
Ypu can ofcourse modify it to suit your needs,
what do you think?
best regards
Thomas A