|
Posted by Steve on 06/06/07 17:37
On 6 Jun, 18:07, Rik <luiheidsgoe...@hotmail.com> wrote:
>
> mysql_query()/mysql_fetch_assoc() etc. could be in the flavour of your
> choice, childof is assumed to be NULL in rootnodes:
>
> function treelist($parent = 0,$level = 0){
> //failsafe:
> if($level > 30){
> trigger_error('function treelist(): nesting too deep ( > 30), self
> referencing item?', E_USER_ERROR);
> exit;
> }
> $where = ($id == 0) ? ' IS NULL ': ' id = '.intval($parent);
> $res = mysql_query('SELECT id,foldername,childof FROM table WHERE
> childof '.$where);
> if(!mysql_num_rows($res)) return '';
> $return = "\n".str_repeat(' ',$level).'<ol>';
> while($row = mysql_fetch_assoc($res)){
> $return .= "\n".str_repeat('
> ',$level).'<li>'.$row['foldername'].treelist($row['id'],$level+1).'</li>';
> }
> $return .= "\n</ol>\n";
> if($level > 1) $return .= str_repeat(' ',$level-1);
> return $return;}
>
Hi thanks for this. I don't seem to be able to make it work. I have
made the root nodes in the database have a NULL ChildOf but each time
I get the "nesting too deep ( > 30), self referencing item" error. Hi
have checked and double checked - and there are no self-referencing
items.
I've tried to debug by checked what $where contains and on each
iteration it just contains IS NULL. What do the ($id==0) and the
'id=" . intval($parent) parts do? There doesn't seem to be an $id
variable declared or set anywhere in the php. I tried changing the
$id==0 to $parent==0 and this produces only the top level list. If I
specify a different "level" this only has the effect of inserting gaps
between each item but it still only returns the top level items.
What I am hoping to achieve is the ability to display the fully
expanded hierarchy.
Any further thoughts???
Best regards, and many thanks,
Steve
Navigation:
[Reply to this message]
|