Hi, I will buy whoever solves this one a well deserved beer because it is driving me crazy trying to puzzle it out. Anyway, I have a site created with CubeCart V3 (I know there are better alternatives but I'm stuck with it this time.) While adding a product the categories are displayed in a html option drop down box and the appropriate one is chosen from the list... The trouble is the categories are displayed in some random order and there are now over 100 categories. You can imagine it is a real chore trying to sort through and find the right one every time a new product is added. I have found the block of code that queries the database and displays the option drop down but I don't know how to get it to sort in ascending alphabetical order. Here is the code block: <?php for ($i=0; $i<count($categoryArray); $i++){ ?> <option value="<?php echo $categoryArray[$i]['cat_id']; ?>" <?php if(isset($results[0]['cat_id']) && $categoryArray[$i]['cat_id']==$results[0]['cat_id']) { echo "selected='selected'"; } ?>> <?php echo getCatDir($categoryArray[$i]['cat_name'],$categoryArray[$i]['cat_father_id'], $categoryArray[$i]['cat_id']); ?> </option> <?php } ?> Code (markup): Are there any PHP geniuses out there that can help? T
Try this <?php for ($i=0; $i<count($categoryArray); $i++){ $categoryOrdered[ strval($i)] = $categoryArray[$i]['cat_name']; } asort($categoryOrdered); ?> <?php foreach ($categoryOrdered as $key => $val){ $i = intval( $key ); ?> <option value="<?php echo $categoryArray[$i]['cat_id']; ?>" <?php if(isset($results[0]['cat_id']) && $categoryArray[$i]['cat_id']==$results[0]['cat_id']) { echo "selected='selected'"; } ?>> <?php echo getCatDir($categoryArray[$i]['cat_name'],$categoryArray[$i]['cat_father_id'], $categoryArray[$i]['cat_id']); ?> </option> <?php } ?> Code (markup): It will sort by 'cat_name'
Thanks for the hlep gviger. Your code looks flawless and I can't see any reason why it shouldn't work but when I edited the file and uploaded it didn't make a jot of difference to the sort order :-( I'm guessing that there must be something else overiding it???? T
Ok, I've sorted it now. I was editing the wrong area of the file :& Much thanks to gviger - Please PM me your Paypal email so I can buy you a beer. T