php + mysql.... ORDER twice?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

php + mysql.... ORDER twice?

Post by Citizen »

Basically I have a query that finds the top 10 results ordered by the number of votes.

Once I have these 10 results, I want to order them by date, not by results.

Can I do this within the mysql query or would it be better to use php?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Like this?

Code: Select all

ORDER BY NO_VOTES DESC, DATE_FIELD DESC LIMIT 0,1
Edit: added limit 0,1
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

Thanks... what does the limite 0,1 do?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Citizen wrote:Thanks... what does the limite 0,1 do?
It was supose to be limit 0,10

This way only the first 10 results are returned ;)
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

Thanks again.

I've used LIMIT before but I'm unsure why there's a 0 in the 0,10

Wouldnt that return 0 results?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

no it says start at the first record.

See what happens when you change zero to another number say 5

LIMIT 5,10
Citizen
Forum Contributor
Posts: 300
Joined: Wed Jul 20, 2005 10:23 am

Post by Citizen »

Thanks!
Post Reply