everisk Posted November 21, 2007 Share Posted November 21, 2007 Hello, I have a recursive function which is running as expected. However, I dont know how could I access the variable in the recursive function outside of the function scope. The variables are in array. Below is my code. Thanks! //get forwarder id $sql = "select * from forward_network where email='$email'"; $tab = mysql_query($sql) or die("Cannot select email"); $row = mysql_fetch_array($tab); $forwarder_id = $row['id']; //find children of forwarder $children = get_children($forwarder_id); print_r($children); function get_children($id) { $sql = "select * from forward_network where parent_id=$id"; $tab = mysql_query($sql) or die("Cannot get children"); if($tab) { //if there is value in $tab or children are found, then store it while($row = mysql_fetch_array($tab)) { $child['id'] = $row['id']; $child['email'] = $row['email']; $child['parent_id'] = $row['parent_id']; $child['level'] = $row['level']; //get children of children ,, recursive print "<pre>"; print_r($child); print "</pre>"; print "<br>"; get_children($row['id']); } } return $child; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.