Jump to content

Order MYSQL Results by Size Order in Php??


Wazuke

Recommended Posts

ORDER BY FIELD(size,'3XL','2XL','XL','L','M','S','XS')

 

Care to elaborate (field() is new to me)? field() returns the index position of size in the '3XL','2XL','XL','L','M','S','XS' list which is thus 0-7 then how does for example ORDER BY 3 help as it would just order by the 3rd column?

ORDER BY FIELD(size,'3XL','2XL','XL','L','M','S','XS')

 

Care to elaborate (field() is new to me)? field() returns the index position of size in the '3XL','2XL','XL','L','M','S','XS' list which is thus 0-7 then how does for example ORDER BY 3 help as it would just order by the 3rd column?

 

Magick ;)

 

size, FIELD(size,'3XL','2XL','XL','L','M','S','XS')

--------------------------------------------

3XL, 1

2XL, 2

XL , 3

L  , 4

M  , 5

S  , 6

XS , 7

ORDER BY FIELD(size,'3XL','2XL','XL','L','M','S','XS')

 

Care to elaborate (field() is new to me)? field() returns the index position of size in the '3XL','2XL','XL','L','M','S','XS' list which is thus 0-7 then how does for example ORDER BY 3 help as it would just order by the 3rd column?

 

Magick ;)

 

size, FIELD(size,'3XL','2XL','XL','L','M','S','XS')

--------------------------------------------

3XL, 1

2XL, 2

XL , 3

L  , 4

M  , 5

S  , 6

XS , 7

 

Thx Mchl Magick indeed ;) I now understand how it works and I'll remember to use that whenever I have a fixed list. Got any resource that contains more of such Magick? Book? Tut?

internet

 

I can never remember how this is used, so when I need I do this:

http://lmgtfy.com/?q=mysql+custom+sort

 

That's not what I meant. I surely hoped there would be some specific document/book that discussed these advanced MySQL features/uses and I actually wanted to know the title of this document/book.

 

Although your lmgtfy turned up some good results :)

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.