Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    136
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ORDER BY sorting wrong..

    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?

    PHP Code:
    <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?
    Code:
    <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>

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    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;

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    136
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wow! That was really bone-headed of me. Thank you for pointing that out


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •