[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
 

Re: [PROGRAMMERING] Rekursion i php



On Sun, 2003-12-21 at 01:04, Jan Andersen wrote:
> Jeg er lige begyndt at programmere php, og vil høre om der er nogen
> hajer der lige ved hvordan man laver en rekursiv metode i php baseret på
> arrays. (det er mit kendskab til arrays i php der kommer lidt til kort
> her).
Heh .. mit kendskab til PHP er nok endnu mindre, men jeg tillader mig at
svare alligevel.
>  
> Problemet er at jeg skal hente nogle data fra mysql og udskrive disse
> rekursivt. Derfor har jeg gemt dem i et array, for at spare requests til
> databasen.
Uhmm .. nu er rekursion jo en underlig størrelse at debugge .. specielt
på en webserver .. en alm. for/while/do skulle vel nok kunne række. 

>  
> Ex. 
> $array = array();
> for ($i=0; $i<$number; $i++) {
>     $id = mysql_result($result,$i,"id");
>     $link = mysql_result($result,$i,"link");
>     $titel = mysql_result($result,$i,"titel");
>     $tekst = mysql_result($result,$i,"tekst");
>     $far = mysql_result($result,$i,"far");
>     $array[$i] = array($id,$titel,$tekst,$link,$far);
> }
>  
> Nu vil jeg så gerne have ”selected” de rækker i arrayet der har far = 0
> og derefter hente dem der har denne rækkes id som far, etc.
>  
> Hvordan gør man nemmest dette i php? (kunne ikke rigtigt finde noget på
> google, formentlig fordi jeg har søgt på det forkerte)
Hvad med sådan her :

foreach ($array as $val)
{
    if($val[5] == 0)
    {
       #Gør noget her når $far er 0
    }
}

/Jimmy
-- 
Jimmy Selgen <sslug@sslug>


 
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] *