Total members 11894 |It is currently Mon Nov 25, 2024 6:35 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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)




Author:
Newbie
User avatar Posts: 23
Have thanks: 1 time
Post new topic Reply to topic  [ 1 post ] 

  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 return more than one value     -  
 Nested function     -  
 array_key_exists function use     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com