Switch to full style
Dynamic open source server-side web development
Post a reply

problem, recursive function using array_merge()

Thu Jul 30, 2009 9:30 am

Recursive function using array_merge():
Here's the problem code:

function findChildren
( $parent ){
$children = array();
$query = "SELECT * FROM atree WHERE parent_id = '$parent'";
$result = mysql_query($query) or die("Query Failed:".$query." Error message:".mysql_error());
$num_of_rows = mysql_num_rows($result);
$children[] = $parent;
"After push: $children <br>";
 $num_of_rows > 0 ){
$get = mysql_fetch_array($result);
"this is the child ";
echo $get["id"]."<br>";
array_merge( $children, findChildren( $get["id"] ) );
"Returning the children of $parent :$children <br>";
return $children;

had a problem where, the that prints the $children[0] element prints fine... it prints out what I set it to by doing the $children[] = $parent

When I print just by echoing $children it's nothing.... also, when the merge is done, it's seeing the 2 array's as nothing, and returns nothing....

But Finding all children in a single parent tree mysql table(layout --> 2 fields, id, parent_id)

Post a reply
  Related Posts  to : problem, recursive function using array_merge()
 problem, recursive function using array_merge()     -  
 recursive function to delete directories     -  
 executeBatch() function problem     -  
 mail function problem     -  
 Feature selection: Statistical and Recursive examples     -  
 recursive string reversal- reverse string     -  
 php function     -  
 finalize() function     -  
 srand function example     -  
 Function Recursion     -  

Topic Tags

PHP Functions