Reply to Re: noob push/merge problem

Your name:

Reply:


Posted by strawberry on 12/01/06 23:19

strawberry wrote:
> I know this is probably completely straightforward but how do can adapt
> this function so as to merge the results of the recursive queries into
> a single, flat array?
>
> function display_children($parent) {
> if($parent == 'null'){
> $query = "SELECT `id` FROM `task` WHERE ISNULL(`parent`);";}else{
>
> $query = "SELECT `id` FROM `task` WHERE `parent`= '$parent';";}
> $result = mysql_query($query);
> while ($row = mysql_fetch_array($result)) {
> display_children($row['id']);
> }
> }
>
> So if the results of the 1st query was 1,2,3
> and the results of the first recursion was 11,21,31
> and the results of second recursion was 118,213,315
>
> I'd end up with array(1,2,3,11,21,31,118,213,315)
>
> As always, any help appreciated.

here's my stab at it. it doesn't work - but i'm not sure why not:

function display_children($parent) {

if($parent == 'null'){
$query = "SELECT `id` FROM `task` WHERE ISNULL(`parent`);";}else{

$query = "SELECT `id` FROM `task` WHERE `parent`= '$parent';";}
$result = mysql_query($query);
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
if ( !is_array($myarray) ) $myarray = array();
$myarray[] = array_push($myarray,$row['id']);
display_children($row['id']);
}
return $myarray;
echo "<br>";
}

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация