-2

I'm trying to do a recursive sql query, searching for all the children of a father and the children of that children, and so on.. The problem with the code below is that it only retrieves the first children tree.

  • I need to save all the emails of the entire tree in an array

    $hermanos = array();
    function obtener($id){
        $res = mysql_query("SELECT email,id FROM usuarios WHERE padre = '$id'", Conectar::con());
        while($row = mysql_fetch_assoc($res)){ 
            if ($row['email'] != 'waiting') {
                $hermanos[] = $row['email'];
                obtener($row['id']);
            }
        }
        return $hermanos;
    }
    $a = obtener($invitado);
    print_r($a);
    
1
  • What's your question? Commented Dec 29, 2013 at 23:28

1 Answer 1

1

From the vague description I think you want another solution. This is called Hierchial data retireval according to db language. I think these kind of recursive queries should be done on db end with procedures/views You can check these links for heirchial data

  1. Sol1 with sql view

  2. Article about Hierarchical data in mysql

  3. another soln with view

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.