I am I missing something or..... I have a table category in which there will be three level (possibly more), I uses ID and parent_id to distinguis between the levels. All values with parentid = 0 are top level categories, those with a parent id = id of another value are child values of that parent category. Sounds easy enough. so my structure looks like this Category 1 id 1 parent_id 0 Sub Category 1 id 2 parent_id 1 Sub Category 2 id 3 parent_id 1 Category 2 id 4 parent_id 0 Sub Category 3 id 5 parent_id 4 SS Category 1 id 6 parent_id 5 Category 3 id 6 parent_id 0 I want to beable to enter a new category and select whether or not it is a new top category or a sub category of an existing category. To do this I have a drop down box containing the values of all the categories. Now to make it more user friendly I want to dispaly the values as they appear above (tree like effect) So I build an array dynamically based on whats in the db (child parent relarionship) First I use the following code to get the top level before I go to the next record I call the category_level() and pass the id of the current top level $query = "select * from category where parent_id = 0 order by id asc"; $lc = 1; while($row = mysql_fetch_array($result)){ $main_id[$lc]= $row["id"]; $title[$lc] = $row["title"]; $defined_category[$main_id[$lc]]="TopLevel_".$title[$lc]; echo $defined_category[$main_id[$lc]]."<br>"; category_level($main_id[$lc]); $lc++; } In the recursive function goes through all child levels to see if there are more sub levels and enters a value for the dynamic array function category_level($id) { global $defined_category; $q = "SELECT * from category WHERE parent_id = $id "; while ($db->next_record()) { $dtitle = $db->f("title"); $did = $db->f("id"); $defined_category[$did]="level_".$dtitle; echo "__".$defined_category[$did]."<br>"; $category_level = category_level($did); } } When I echo the values of the array the values are displayed correctly in the correct order (as above). But the actual drop down box displays the lowest level values first then the next level higher and then the top level. Is there any way of ordering this select box? Any help much appreciated.