Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Order By [PHP & MySQL]

  • 16-03-2003 8:59pm
    #1
    Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭


    Hey There,

    Ok i've a search query in mysql and I want to arrange the rows in a certain order.

    Ok the rows contain a field called "package" and the values can be bronze,silver or gold. So i want a way so that all the gold will go to the top of the search and the silver 2nd and gold last.

    So it would be like

    "SELECT * FROM `table` ORDER BY" I dont know how to finished this query so need help.

    Thanks in advance


Comments

  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    Admittedly, I haven't much experience with SQL, but I don't think you can, since, gold comes between silver and bronze, so any attempt to order it would simply put gold in the centre.

    Perhaps two separate statements could fulfill your needs;

    SELECT winner_name, medal FROM myTable WHERE medal='gold' ORDER BY winner_name DESC

    Then half-create your table with these values, and then do the query;

    SELECT winner_name, medal FROM myTable WHERE medal='bronze' OR medal='silver' ORDER BY medal ASC, winner_name DESC

    then fill in the end of your table.

    That just my 2c :)


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Thanks,

    tho i've come up with another method, just call gold 1, silver 2 and bronze 3 and then they will automatically order by that. but i am so damn lazy to go changing to script now. I'll wait till someone complains on the site. I've everything randomised so the search never ends lol. Like always Next 20 same showing up every round hehehe.


  • Registered Users, Registered Users 2 Posts: 912 ✭✭✭chakotha


    It would be quick enough

    run

    update myTable set package=1 where package='Gold';
    update myTable set package=2 where package='Silver';
    update myTable set package=3 where package='Bronze';

    from phpMyAdmin or shell or script and change form to

    <select name=package>
    <option value=0>Choose
    <option value=1>Gold
    <option value=2>Silver
    <option value=3>Bronze
    </select>

    and

    <?
    $sql="select * from myTable where [whatever] order by package";
    ...
    ?>

    Then there'e edit form tho...


Advertisement