Page 1 of 1

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

Posted: Tue Nov 20, 2012 7:37 am
by jcl1290
My current code is:
$sql = "SELECT * FROM juarez WHERE categoriesID = 4 ORDER BY RAND() LIMIT 1";
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 :(

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

Posted: Sun Nov 25, 2012 1:40 am
by jacek
Well the RAND() function accepts a seed parameter so you could probably combine it with the date functions
ORDER BY RAND(YEAR() * 1000 + WEEK())
for example

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