Have you consider to write a recursive
function to explore all the sublevels?
>-----Original Message-----
>From: Andrew.Martin [mailto:[EMAIL PROTECTED]]
>Sent: Friday, September 07, 2001 11:43 AM
>To: [EMAIL PROTECTED]
>Subject: [PHP-WIN] array problems
>
>
>
>I want to build an array dynamically from a database.
>I have a structure where there is a top level, under which
>there can be a
>sub level and a sub-sub level etc...
>
>e.g
>
> Top Level 1 id =1 parent id =0
> Sub Level 1.1 id =2 parent id =1
> Sub Level 1.2 id =3 parent id =1
> SubSub Level 1.2.1 id =4 parent id = 3
> SubSub Level 1.2.2 id =5 parent id = 3
> .
> .
> SubSub Level 1.2.2 id =n parent id = 3
>
> Sub Level 1.3 id =n parent id =1
> Top Level 2 id =n parent id =0
>
>
>
>I want to loop through the entire table (for sub levels parent
>level = id of parent level) and display the details as above.
>
>Initally I have a statement selecting the top level (where
>parent id = 0)
>
> $query = "select * from category where parent_id = 0 order
by id asc";
> $result=$db->query("$query") or die("Select Failed!");
>
> $counter = 1;
> while($row = mysql_fetch_array($result)){
> $main_id[$counter] = $row["id"];
> $title[$counter] = $row["title"];
>
> //build array
>
>$defined_category[$main_id[$counter]]=$title[$counter];
>
> //search for lower level.....
>
> $counter++;
> }
>
>This works fine, my problem is when I try to search for lower
>levels. I have tried another 'while loop but I get errors!
>Anyone know a decent solution for this?
>
>Andrew
>
>
>
>
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]