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

problem, recursive function using array_merge()

Mon Jul 13, 2009 10:45 am

Hi.

Here's the problem code:
php 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;
echo"test:".$children[0]."<br>";
echo"After push: $children <br>";
if( $num_of_rows > 0 ){
for($i=0;$i<$num_of_rows;$i++){
$get = mysql_fetch_array($result);
echo"this is the child ";
echo $get["id"]."<br>";
array_merge( $children, findChildren( $get["id"] ) );
}
}
echo"Returning the children of $parent :$children <br>";
return $children;
}

Now I have a problem where, the that prints the $children[0] element prints fine... it prints out what I set it to by doing thephp code
$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....

DO I have a spelling mistake in variables? dno't think so... anyone help me on this, I'm completely stumped.

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     -  
 mail function problem     -  
 executeBatch() function problem     -  
 Feature selection: Statistical and Recursive examples     -  
 recursive string reversal- reverse string     -  
 php function     -  
 Function Recursion     -  
 Using the array_slice () Function     -  
 Function return more than one value     -