BradG
BradG

Reputation: 740

How to order values from SQL in drop down aphabeticallty and place the value "Other" at the bottom

I have somewhat simple question but I am unable to figure it out myself.

In my PHP file I order the values from SQL alphabetically using the following command:

$qry_makes  = "SELECT * FROM ".$tblprefix."makes Where type ='1' and status ='1' ORDER BY title ASC";

This arranges the values alphabetically, which is what I want. The problem is that this places the value "Other" in the middle of the dropdown and I want to place it at the bottom. I did some research I found that I can use this:

order by
case when value= 'Other' then 1 else 0 end,
value

I tried to play with this code and embed it in mine but I am missing something.

Any help will be appreciated, thank you!

Upvotes: 2

Views: 77

Answers (2)

CompanyDroneFromSector7G
CompanyDroneFromSector7G

Reputation: 4517

ORDER BY CASE WHEN value= 'Other' THEN 1 ELSE 0 END, title ASC

Upvotes: 3

xate
xate

Reputation: 6379

Other should not be in your database.

you can just write

<option name="Other">Other</option>

at the end, after all your SQL entries.

Upvotes: 3

Related Questions