Displaying a family tree

Discussion in 'PHP' started by alimoses, Sep 27, 2010.

  1. #1
    I have table 'children' with column id, name. the table store information about a father's children. this father has great grand children. I want to pick a particular child and display his children, grand children, great grand children in a family tree.
    Please help me out
     
    alimoses, Sep 27, 2010 IP
  2. axelay

    axelay Peon

    Messages:
    54
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Recursivity will help you on this.
    Do a search on this forum, I have posted something fairly similar :)

    In short you have a function that takes an Id as parameter like so:
    function getChildren ($id)
    {
      $sql = "SELECT * FROM children WHERE father_id = $id";
      foreach of the children
      {
        echo $child['name'];
        getChildren ($child['id']);
      }
    }
    Code (markup):
    This is pseudo-code heh but should point you in the right direction ;)

    aXe
     
    axelay, Sep 27, 2010 IP