Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2010
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I use recursion to get a family tree

    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

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,799
    Thanks
    78
    Thanked 4,410 Times in 4,375 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •