Recursive PHP script +JavaScript
How do you write a script that dynamicly create thisoutput:
1
1_1
1_2
1_3
1_3_1
1_3_2
1_3_3
2
2_1
2_1_1
2_1_2
2_1_3
3
3_1
3_2
3_3_1
4
5
This is my recursive function:
Takes data from a database
(id, name, _parent)
I need the number system over before
$name->name for a JavaScript array
--------------------------------------------------------------------------------
<?
function buildTree($id = 0, $depth = 1) {
global $db;
// $s = 1;
$names = $db->get_results("SELECT * FROM names2 WHERE _parent = ".$id." ORDER BY pri");
$foo = count($names);
if ($foo == 0) {
}
else {
foreach ($names as $name) {
echo "".$path." ".str_repeat(">", $depth)."<strong>".$name->name."</strong> ... <br>";
buildTree($name->id, $depth + 1);
}
}
}
?>