Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

A Little Code Help


gaspower

Recommended Posts

Hello,

 

I have a import utility, 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,categories_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());

}

 

 

while($get_upper_category_query->fetchInto($upper_category_row)){

$parent = $upper_category_row[1];

$category_string = $upper_category_row[2] ."->".$category_string;

}

 

}

 

$category_string = ltrim($category_string,'->');

 

echo "<OPTION>".$category_string;

 

}

 

?>

</SELECT>

Link to comment
Share on other sites

There is a contribution called "attribute sorter" that will do what you want. I don't know if it will mess up what you have already done though. Worth checking out.

 

Peter

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...