Code:
function displayTree(&$array,$indent='') {
echo "$indent".$array['letter']."\n";
foreach($array['child_array'] as $child)
$this->displayTree($child,$indent);
}
$result=TreeRow::$dbLink->query("SELECT * FROM `" . MYSQLI_TEST_TABLE . "` WHERE 1 ORDER BY tree_index ASC, treesort_index ASC");
$rows = array(0=>array('child_array'=>array()));
while($row=$result->fetch_assoc()) {
$row['child_array']=array();
$rows[$row['my_index']]=$row;
$rows[$row['parent_index']]['child_array'][$row['my_index']]=&$rows[$row['my_index']];
}
displaySubtree($rows[0]);
AWESOME! Reference variables make this so much easier.
(the above code fetches rows from an associative database and returns them reorganized into their tree structure)
Output:
Code:
a
b
c
d
e
f
g
h
i
j
k
l
m
n
Bookmarks