Total members 11890 |It is currently Sat Jun 15, 2024 5:50 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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)




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     -  
 Using the array_slice () Function     -  
 Function return more than one value     -  
 Nested function     -  



Topic Tags

PHP Functions
cron





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