The following functions are intended to return a set of ids, and their
respective children, as a single dimensional array ($ids), however, I'm
getting nothing. I think the problem is that the results are being
returned prematurely - before the recursion has finished - but I'm not
quite sure how to fix that. Any help appreciated.
Note: Also posted at alt.php.mysql
function array_merger($a ,$b){
$count = count($b);
for ($i = 0; $i < $count; $i++) {
$a[]=$b[$i];
}
return $a;
}
function display_childre n($parent) {
$ids=array();
$childres=array ();
if($parent == 'null'){
$query = "SELECT `id` FROM `task` WHERE ISNULL(`parent` );";
}else{
$query = "SELECT `id` FROM `task` WHERE `parent`= '$parent';";}
$result = mysql_query($qu ery);
while ($row = mysql_fetch_arr ay($result,MYSQ L_ASSOC)) {//
$ids[]=$row['id'];
$childres[]=display_childr en($row['id']);
}
$count=count($c hildres);
for($i=0;$i<$co unt;$i++){
$ids=array_merg er($ids,$childr es[$i]);
}
return $ids;
}
respective children, as a single dimensional array ($ids), however, I'm
getting nothing. I think the problem is that the results are being
returned prematurely - before the recursion has finished - but I'm not
quite sure how to fix that. Any help appreciated.
Note: Also posted at alt.php.mysql
function array_merger($a ,$b){
$count = count($b);
for ($i = 0; $i < $count; $i++) {
$a[]=$b[$i];
}
return $a;
}
function display_childre n($parent) {
$ids=array();
$childres=array ();
if($parent == 'null'){
$query = "SELECT `id` FROM `task` WHERE ISNULL(`parent` );";
}else{
$query = "SELECT `id` FROM `task` WHERE `parent`= '$parent';";}
$result = mysql_query($qu ery);
while ($row = mysql_fetch_arr ay($result,MYSQ L_ASSOC)) {//
$ids[]=$row['id'];
$childres[]=display_childr en($row['id']);
}
$count=count($c hildres);
for($i=0;$i<$co unt;$i++){
$ids=array_merg er($ids,$childr es[$i]);
}
return $ids;
}
Comment