Jump to content

Order by something THEN rand() ?


TEENFRONT

Recommended Posts

Hey

 

I have a custom made link script. And i wish to send a link out to the top 3 referrers.

 

my db is like this

 

id | siteurl | hits_in

1  | www. | 5

2  | www. | 2

13 | www. | 8

 

So i first want to ORDER BY hits_in DESC    so i get results ordered by highest hits in, then LIMIT 5

 

Soooo... i get the top 5 referrers from the list. But here i get stuck. I just want to choose 1 rand() result  out of the top 5 from the previous ORDER BY.

 

I need a query like

 

ORDER BY hits_in DESC LIMIT 5 rand() LIMIT 1

 

I know thats not logical so how do i tackle this?

 

Mny thanks!

Link to comment
https://forums.phpfreaks.com/topic/110870-order-by-something-then-rand/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.