Jump to content

PHP/MYSQL ORDER BY


imallika

Recommended Posts

Hello,

I have a drop down list that i want to oder alphabetically, and the entries are pulled up from a table.

The constraint is that, all entries except the entry 'other' must appear sorted alphabetically. 'Other' should appear at the bottom.

I tried using a constant SERIAL_ID, but entries are added into the database and the alphabetization goes off, since they get sorted by SERIAL_ID. I also tried using the WHERE, which I tried equating to any entry except "other", which did not work.

Any help/suggestions please?

                                          -Mallika

 

Link to comment
https://forums.phpfreaks.com/topic/72951-phpmysql-order-by/
Share on other sites

So you're selecting a list of items from a database which you want to sort for output as a drop down list, and then add in the other option on the end? Without your current code i cant offer more help than that it will look something like:

 

<?php
$sql = "SELECT `entry` FROM `yourtable` WHERE `entry` != 'other' ORDER BY `entry`";
$result = mysql_query($sql) or die(mysql_error());
echo '<select name="select field">';
while($row = mysql_fetch_assoc($result)){
echo '<option value="'.$row['entry'].'">'.$row['entry'].'</option>';
}
echo '<option value="other">other</option>';
?>

Link to comment
https://forums.phpfreaks.com/topic/72951-phpmysql-order-by/#findComment-367918
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.