SQL order by problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
cczernia
Forum Newbie
Posts: 20
Joined: Tue May 16, 2006 2:00 pm
Location: San Diego, CA

SQL order by problem

Post by cczernia »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I have an sql statement that orders a pull down menu using sql "order by" in product_info (from oscommerce).

Code: Select all

$products_options_query = tep_db_query("select pa.options_id, pa.options_values_id, pa.options_values_price, pa.price_prefix, po.options_type, po.options_length, pot.products_options_name, pot.products_options_instruct from
           " . TABLE_PRODUCTS_ATTRIBUTES  . " AS pa,
           " . TABLE_PRODUCTS_OPTIONS  . " AS po,
           " . TABLE_PRODUCTS_OPTIONS_TEXT  . " AS pot
           where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "'
             and pa.options_id = po.products_options_id
             and po.products_options_id = pot.products_options_text_id and pot.language_id = '" . (int)$languages_id . "'
           order by pa.products_options_sort_order
           ");

This will order the values of the product attributes. If you want to order the product options you change "pa.products_options_sort_order" to "po.products_options_sort_order".

My question is how do you change it if you want to order both?



Just in case I need to define myself here is how I'm labeling the attributes...
Pull down menus

Frames (option)
Gold (value)
Silver (value)
Mahagony (value)

Size (option)
11x14 (value)
14 x 17 (value)

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ORDER BY accepts multiple inputs. Separation is a comma.
Post Reply