PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| function showCustomers( $searchparent, $level ){ global $eas; $thisparent = ""; $query_customers = "select * from contact where ouder_ID= ". $searchparent ." order by naam"; $eas->selectQuery( $query_customers ); $result_customers = $eas->result; if( $eas->numRows() != 0 ){ //run through results for( $i=0 ; $i < count($result_customers) ; $i++ ){ $output = ""; //there are children found, descending one level if( $thisparent != $searchparent ){ //$searchparent contains the ouder_ID we're searching for this call //found a valid child, so descend one level //$thisparent = $searchparent descend only one time this for loop $thisparent = $searchparent; $level++; } //align it a little for( $j=0 ; $j < $level ; $j++ ){ $output .= " "; } $output .= $result_customers[$i]["naam"] ."<br>"; print( $output ); //recursion showCustomers( $result_customers[$i]["ID"], $level ); } } } |
Ik heb een recursieve functie geschreven om een "boom" achtige structuur te tekenen. Hij werkt prima zo, maar ik vraag me af of wat ik bedacht heb ook de logischte & efficientste manier is om dit probleem te tackelen!
dus... wat vinden jullie van deze opzet?
[ Voor 40% gewijzigd door Verwijderd op 06-11-2003 10:17 ]