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;
}

?>


> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED]
> m] On Behalf Of Chih-Lii Chen/Trans-EZ/TW
> Sent: Tuesday, June 12, 2001 9:24 PM
> To: [EMAIL PROTECTED]
> Subject: recursive select
> 
> 
> Hi,
> 
> I'm having a slight problem trying to figure out some logic. I have a 
> mySQL table that contains 3 columns (child, category, parent). 
> What I like to do is retrieve all the childrens of the parent 
> and store 
> them in an php array.
> 
> Any advies on this issue will be very helpful.
> 
> Thanks in advance for the help.
> 
> Chih-Lii
> 


---------------------------------------------------------------------
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