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