Page 1 of 1

Mysql Order By Problem

Posted: Tue Apr 22, 2003 5:51 pm
by anomaly
I'm trying to get mysql to order a set of values extracted from the database in numerical order for a drop down menu. It does this, but for some reason it only reads the first digit of the number, therefore it places 10 before 9 etc..

Here is the code:

Code: Select all

$products_options_name = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from products_options popt, products_attributes patrib where patrib.products_id='" . $HTTP_GET_VARSї'products_id'] . "' and patrib.options_id = popt.products_options_id");

      echo '<b>' . TEXT_PRODUCT_OPTIONS . '</b><br>';
      echo '<table border="0" cellpading="0" cellspacing"0">';

      while ($products_options_name_values = tep_db_fetch_array($products_options_name)) &#123; 
        $selected = 0;

//this is the thing i'm having the problem with:

        $products_options = tep_db_query("select products_options_values.products_options_values_id, products_options_values.products_options_values_name, products_attributes.options_values_price, products_attributes.price_prefix from products_attributes, products_options_values where products_attributes.products_id = '" . $HTTP_GET_VARS&#1111;'products_id'] . "' and products_attributes.options_id = '" . $products_options_name_values&#1111;'products_options_id'] . "' and products_attributes.options_values_id = products_options_values.products_options_values_id ORDER BY products_options_values.products_options_values_name ASC");
        
echo '<tr><td>' . FONT_STYLE_MAIN . $products_options_name_values&#1111;'products_options_name'] . ':&nbsp;</font></td><td>' . "\n" . '<select name ="id&#1111;' . $products_options_name_values&#1111;'products_options_id'] . ']">' . "\n"; 

        while ($products_options_values = tep_db_fetch_array($products_options)) &#123;
          echo "\n" . '<option name="' . $products_options_name_values&#1111;'products_options_name'] . '" value="' . $products_options_values&#1111;'products_options_values_id'] . '"';
          if ( ($products_options_values&#1111;'options_values_price'] == 0 && $selected == 0) || ($cart->contents&#1111;$HTTP_GET_VARS&#1111;'products_id']]&#1111;'attributes']&#1111;$products_options_name_values&#1111;'products_options_id']] == $products_options_values&#1111;'products_options_values_id'])) &#123;
            $selected = 1;
            echo ' SELECTED';
          &#125;
            echo '>' . $products_options_values&#1111;'products_options_values_name'];
            if($products_options_values&#1111;'options_values_price'] != "0.00")&#123;
            echo '&nbsp;(' . $products_options_values&#1111;'price_prefix'] .'$'. $products_options_values&#1111;'options_values_price'] .')&nbsp</option>';
            &#125;
        &#125;;
        echo '</select></td></tr>';
      &#125;
      echo '</table>';
Thanks for your help!

Posted: Tue Apr 22, 2003 9:45 pm
by chris22
Sounds like the field you're sorting on is not a numeric field. The character 1 comes before 9 in the "ascii alphabet". Try changing your field to a float or int.