Discussions
Categories
Groups
Advertisement
Child Item
Home
Topics
Technology & Internet
Software & Web Development
Development
Order By [PHP & MySQL]
Webmonkey
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
Find more posts tagged with
Quick Links
All Categories
Recent Posts
Activity
Unanswered
Groups
Best Of
Advertisement
Advertisement
Comments
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
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.
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...