[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
 

Rekursion i php



Hej
 
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).
 
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.
 
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)
 
Jeg fandt ud af at det var muligt at sortere dem sådan her.. derefter er
det vel bare at fortsætte til far ikke længere har værdien 0. Men det er
lidt omsonst at kalde denne funktion igen og igen for hver gang for at
sortere listen efter en ny rækkefølge afhængigt af id…
 
foreach ($array as $val)
{
     $sortarray[] = $val[5];
}
array_multisort($sortarray,$array);
 
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] *