Hello,

I have a import utility for a shopping cart, but for some reason on a
particular drop down box, it sorts randomly. Can someone look at the below
code and let me know what I missed to sort it alphabetically.

Thanks JR

<TD class='main' width='15%'>Categories:</TD>
<!--<TD><INPUT TYPE="TEXT" NAME="categories"></TD>-->
<?php
$cat_parents_sql="SELECT distinct(parent_id) FROM categories";

//put the parents in an array
$parents_array = $db->getAll($cat_parents_sql);

//now get a list of all the bottom level sub categories
$bottom_level_sql = "SELECT categories.categories_id,categories.parent_id,
categories_name
FROM categories, categories_description
WHERE categories.categories_id = categories_description.categories_id
AND categories.categories_id not in (";
foreach($parents_array as $parent_id){ $bottom_level_sql .=
$parent_id[0].','; }

$bottom_level_sql = rtrim($bottom_level_sql, ',');

$bottom_level_sql .= ") order by categories_name asc";

$bottom_level_query = $db->query($bottom_level_sql);
if (DB::iserror($bottom_level_query)){ die("'".$bottom_level_sql."'
".$bottom_level_query->getMessage()); }
?>
<TD><SELECT name="category">
<?php

while($bottom_level_query->fetchInto($bottom_level_row)){
$category_string = $bottom_level_row[2]." (".$bottom_level_row[0].")";

$parent = $bottom_level_row[1];
while($parent != 0){
$get_upper_category_sql = "SELECT
categories.categories_id,categories.parent_id,cate gories_name
FROM categories,categories_description
WHERE categories.categories_id = categories_description.categories_id
AND categories.categories_id = ".$parent." order by categories_name asc";

$get_upper_category_query = $db->query($get_upper_category_sql);
if (DB::iserror($get_upper_category_query)){
die("'".$get_upper_category_sql."'
".$get_upper_category_query->getMessage());
}