Forum Moderators: coopster

Message Too Old, No Replies

Parse error: syntax error, unexpected T_LNUMBER, expecting ')' .

working on adjacency list model tree navigation

         

deejay

9:00 pm on Jun 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Alrighty then.. hairpulling time.

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?

eelixduppy

10:45 pm on Jun 10, 2006 (gmt 0)



Why wouldn't you just call the function with a line similar to this?:
display_children('%', 0);
I don't see why it's necessary to change the definition of the function.

deejay

8:12 pm on Jun 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



eelixduppy, you are of course quite right... once I figured out just what you were saying.

What I was missing was an echo statement AFTER the function to call the function - which is where the parameters go.

yes, I am that much of a newb at this stuff. :)

Thank you.