Jump to content

How to sort properly


CincoPistolero

Recommended Posts

Hi all,

I have numbered data over ten rows in the database. When I pull the data out via a select statement, I want to be able to choose how it is ordered in a dropdown box. I don't want the order by id ASC, and I don't want it to order numerically because that makes it wrong. And I don't want it alphabetically. Below are examples of the output of two different dropdowns. My question, is there a magical way to choose the order of things after entering data in the db, or do I have to add and extra field to the table like sortOrder.

 

Examples of output

10 inches

12 inches

20 inches

8 inches

I'd want the 8 at the top since it is the smallest size

------

Mahogany

Birch

Laquer

Satin

Maple (Standard)

I'd want the Maple up top because it is the standard

 

Thanks for any help, currently I just do a select * from table order by ID ASC

Link to comment
https://forums.phpfreaks.com/topic/141894-how-to-sort-properly/
Share on other sites

I may be wrong, but if ORDER BY XXX ASC does not get you what you want, then I think your best bet would be to add a field in the DB to sort by. You may place the numbers in there as 10, 20, 30, 40, 50 etc... which would allow you to place items in between if you added new item later.

 

Nate

Link to comment
https://forums.phpfreaks.com/topic/141894-how-to-sort-properly/#findComment-742973
Share on other sites

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.