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:
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;
}
 


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     -  
 mail function problem     -  
 executeBatch() function problem     -  
 Feature selection: Statistical and Recursive examples     -  
 recursive string reversal- reverse string     -  
 php function     -  
 array_key_exists function use     -  
 Using include function     -  
 Function Overloading     -  

Topic Tags

PHP Functions