-1

On my OSCommerce website I'm using QTPro. Its a clothing store and I have a drop down of different sizes. 1x, 2x, etc. Right now, they're in whatever order. I want them to be in numerical/alphabetical order all the time. It was 'fixed' with the latest update, but it didn't work for me at all. Here's the code that sorts it.

//////////////////////

$q=tep_db_query("select ps. products_stock_id, ps.products_id, ps.products_stock_attributes, ps.products_stock_quantity, pov.products_options_values_id, pov.language_id, pov.products_options_values_name from " . TABLE_PRODUCTS_STOCK . " ps, products_options_values pov where ps.products_id=" . $VARS['product_id'] . " and pov.products_options_values_id = substring_index(ps.products_stock_attributes, '-', -1) order by pov.products_options_values_name desc");
    while($rec=tep_db_fetch_array($q)) {
      $val_array=explode(",",$rec[products_stock_attributes]);
      echo "<tr>";
      foreach($val_array as $val) {
        if (preg_match("/^(\d+)-(\d+)$/",$val,$m1)) {
          echo "<td class=smalltext>&nbsp;&nbsp;&nbsp;".tep_values_name($m1[2])."</td>";
        } else {
          echo "<td>&nbsp;</td>";
        }
      }
      for($i=0;$i<sizeof($options)-sizeof($val_array);$i++) {
        echo "<td>&nbsp;</td>";
      }
      echo "<td class=smalltext>&nbsp;&nbsp;&nbsp;&nbsp;$rec[products_stock_quantity]</td><td>&nbsp;</td></tr>";
    }
    echo "<tr>";
    reset($options);
    $i=0;
    while(list($k,$v)=each($options)) {
      echo "<td class=dataTableHeadingRow><select name=option$k>";
      foreach($v as $v1) {
        echo "<option value=".$v1[1].">".$v1[0];
      }
      echo "</select></td>";
      $i++;
    }
  } else {
    $i=1;
    echo "<td class=dataTableHeadingContent>Quantity</td>";
  }
  echo "<td class=dataTableHeadingRow><input type=text name=quantity size=4 value=\"" . $db_quantity . "\"><input type=hidden name=product_id value=\"" . $VARS['product_id'] . "\">&nbsp;</td><td width=\"100%\" class=dataTableHeadingRow>&nbsp;<input type=submit name=action value=" . ($flag?"Add":"Update") . ">&nbsp;</td><td width=\"100%\" class=dataTableHeadingRow>&nbsp;</td>";
?>

/////////////////////////////

I can't make heads or tails of it, but is there anything there that would not work the way I want it to?

Thanks.

Edit:

I've narrowed it down to this line, I just need a way to sort this.

$products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'");

Jeff
  • 1
  • 2

1 Answers1

0

That will sort by the name ascending. Try it descending by changing the "asc" to "desc".

Ruby
  • 528
  • 3
  • 14
  • Tried that and it did nothing. What could be overwriting this? I'll add the rest of the code up top. – Jeff May 10 '14 at 18:24
  • Try echoing the result of the database query and seeing if it's coming out in the right order? Nothing seems to be wrong. – Ruby May 10 '14 at 18:29
  • Well, that helped as since the echo didn't appear, I'm looking in the wrong spot all together. So it must be in this line that its not sorting properly; $products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'"); – Jeff May 10 '14 at 19:15