...

View Full Version : ORDER BY sorting wrong..



bphein1980
07-30-2006, 09:06 PM
I have this written to populate a select menu from a database. I need the menu ordered a specific way, but it is causing one small problem... the value of "All" needs to be listed first in the menu, but for some reason it is always getting placed last. I cannot figure out why when in the ORDER BY part i specifically say it should come first. Any ideas?


<select name="division">
<?php
$result_div = mysql_query("SELECT * FROM records_divisions ORDER BY FIELD(division,'all','open','teen','junior','sub-master','master 40-49','master 50+')");
while($r_div = mysql_fetch_array($result_div))
{
$div = $r_div["division"];

if (strtolower($div) == 'all'){
$option = "<option value=''>Choose One";
}else{
$option = "<option value='$div'>$div";
}
echo "$option\n";
}
?>
</select>

This is how the code is currently writting on the page. As you can see the option for 'all' (which just writes a blank option 'choose one') is being placed at the bottom of the list. How come?


<select name="division">
<option value='Open'>Open
<option value='Teen'>Teen
<option value='Junior'>Junior
<option value='Sub-Master'>Sub-Master
<option value='Master 40-49'>Master 40-49
<option value='Master 50+'>Master 50+
<option value=''>Choose One
</select>

Brandoe85
07-30-2006, 09:13 PM
Without looking at your logic, why not forget about putting that one in the db since it's always their? Echo it out first before you do your db query?

Good luck;

bphein1980
07-31-2006, 11:45 PM
Wow! That was really bone-headed of me. Thank you for pointing that out :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum