Total members 10262 | Gratitudes |It is currently Thu May 24, 2012 5:35 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: problem, recursive function using array_merge()
PostPosted: Thu Jul 30, 2009 9:30 am 
Offline
Newbie
User avatar

Joined: Fri Jun 26, 2009 5:50 am
Posts: 23
Has thanked: 0 time
Have thanks: 1 time

Hi.

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;
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 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....

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)

_________________
Thanks & regards
Lokananth
[url "http://www.mioot.com"]Live Chat Software[/url] By miOOt


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 JavaScript fade out problem
 problem with JcheckBox method
 client server problem
 problem
 Matlab SVM training problem
 I have a serious virus/trojan problem, anyone pls?
 i have problem
 Windows problem!!!
 Problem with skymiles_red
 Question problem

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team