RE: [PHP-WIN] array problems

From: Date: Fri, 07 Sep 2001 09:50:57 +0000
Subject: RE: [PHP-WIN] array problems
Groups: php.windows 
Request: Send a blank email to php-windows+get-9226@lists.php.net to get a copy of this message
Have you consider to write a recursive function to explore all the sublevels? >-----Original Message----- >From: Andrew.Martin [mailto:Martin.Andrew@kpmg-ct.com] >Sent: Friday, September 07, 2001 11:43 AM >To: php-windows@lists.php.net >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 > > > >

« previous php.windows (#9226) next »