On 13-Jun-01 Alok K. Dhir wrote:
> Ah recursion.  Nothing like it to get your mind tied up in knots... :)
> 
> Try this - untested, but this is the basic idea, and it or something
> like it should work.  Call the function with the node you want to start
> from and the array you want the results to land in...  Like so:
> 
> <?
> 
> getCategories($startingNodeID,$targetArray);
> 
> function getCategories($node,&$array) {
>       global $dbh;
>       $sql="select child,category from table where parent=$node";
>       $sth=mysql_query($sql,$dbh);
>       while ($res=mysql_fetch_assoc($sth)) {
>               $array[]=$res[category];
>               getCategories($res[child],$array);
>       }
>       return;
> }
> 
> ?>
> 

 ... and stomp all over the result-set; getCategories() should open/close
a local connection to the db server.

Regards,
-- 
Don Read                                       [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to