ORDER BY RAND() time interval? Weekly? Daily? Custom?

Post here if you need help with SQL.
Post Reply
jcl1290
Posts: 1
Joined: Tue Nov 20, 2012 7:32 am

ORDER BY RAND() time interval? Weekly? Daily? Custom?

Post by jcl1290 »

My current code is:

[syntax=php]$sql = "SELECT * FROM juarez WHERE categoriesID = 4 ORDER BY RAND() LIMIT 1";[/syntax]

I need to seed the rand value to something that would make it get a new random row EACH hour, each day, and each week.
each sql query goes in different pages. I dont know where to start, can anybody help me please? I want to display a random row in a page in one page, a daily random in another and a weekly random in another. Please help me :(
Last edited by jacek on Sun Nov 25, 2012 1:35 am, edited 1 time in total.
Reason: code tags...
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: ORDER BY RAND() time interval? Weekly? Daily? Custom?

Post by jacek »

Well the RAND() function accepts a seed parameter so you could probably combine it with the date functions

[syntax=sql]ORDER BY RAND(YEAR() * 1000 + WEEK())[/syntax]
for example

Remember that the use of the RAND() function like this is pretty slow for large tables though.
Image
Post Reply