PDA

View Full Version : How do I use recursion to get a family tree



Staggan
12-09-2011, 11:06 AM
Hello

I am trying to create a family tree, parents / grandparents etc, of a single person...

My database etc is already working but I cannot find any working examples that I can make sense of...

Each of my records has a name, dob and id of each parent....

How can I get X generations from this..

I thought something like this might work..

GetParents

For each parent GetParents

And so on...

But I have no idea how to put this into code...


Any suggestions to put me on the right line would be greatly appreciated

Thanks

Old Pedant
12-09-2011, 08:32 PM
Not to ask a sillly question...why is this in the JavaScript forum?

I would think you would be asking this in one of the database forums, depending on what database you are using.

aina
12-09-2011, 08:58 PM
function getParent(current) {
// ...
getParent(current.mother);
getParent(current.father);
// ...
}

Be careful about recursion and variable creation. each variable in the function will be duplicated by the depth of the recursion