[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

SV: [PROGRAMMERING] Rekursion i php



> $array=array();
> while ($row=mysql_fetch_assoc($result)){
>    $array[$row['far']][]=$row;
> }

Smart.. 

> function hent_unger($far){
>   global $array;
>   if (!isset($array[$far]){
>     return;
>   } else {
>     echo "<ul>\n";
>     foreach ($array[$far] as $punkt){
>       echo "<li>{$punkt['titel']}</li>\n";
>       hent_unger($punkt['far']);
>     }
>     echo "</ul>";
>   }
>}

Kan man godt have flere rækker med samme id? Eller har jeg ikke helt
forstået arrays i php endnu. Ser lidt ud som om at det er det der sker.
Altså gennemløbe et array med id=far og så udskrive dette.

Men ellers set det umiddelbart rigtigt ud. Og "burde" virke... 
Dog mangler der lige en ")" i linien
	if (!isset($array[$far]){

den tog mig lige lidt tid at finde:-)
Men når man afvikler det virker det som om man ryger i en uendelig
løkke:-(

Fandt dog selv fejl efter jeg havde skrevet et langt brev hvor jeg
prøvede at beskrive præcist hvad jeg ville:-)

hent_unger($punkt['far']); skal være hent_unger($punkt['id']); i stedet
for..:-)

Så spiller det..

Tusind tak for hjælpen

Hilsen

Jan




 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:43 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *