Forum Moderators: coopster
Have just recently started learning php/mysql, and going well so far - have the backbone of the website I want to build, but now I need a menu tree.
I'm working on the 'Storing hierarchical data in a database' article at sitepoint, aiming to use a 'modified pre-order tree traversal' system, but I kept getting an error (and I admit to being confused about what parts of the script I should customise with my field names, etc).
SO. I have backed up and am working through from the start of the article, and am trying the adjacency list model. Seems I can't get past the second line of code though.
nb: somewhere in the process I caved and renamed my table and fields to the same as theirs.. so my table name is 'tree', field names 'title' and 'parent'. The only difference being that my title and parent fields are integers, as I also have a field 'catname' which will ultimately be the one I want to display.
So here is their sample code:
<?php
// $parent is the parent of the children we want to see
// $level is increased when we go deeper into the tree,
// used to display a nice indented tree
function display_children($parent, $level) {
// retrieve all children of $parent
$result = mysql_query('SELECT title FROM tree '.
'WHERE parent="'.$parent.'";');
// display each child
while ($row = mysql_fetch_array($result)) {
// indent and display the title of this child
echo str_repeat(' ',$level).$row['title']."\n";
// call this function again to display this
// child's children
display_children($row['title'], $level+1);
}
}
?>
According to the article, to run the whole tree, the first line (line 24) is changed to:
function display_children('', 0)
which produces the error:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /***/public_html/updcats.php on line 24
uhh. help?