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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.