PDA

View Full Version : how to display a topic randomly after one day


amir
05-03-2006, 04:54 PM
hi all
i have a table named essays and i have many essays in that table. what i wanna do is to write a query
"which takes a different essay at every other day randomly".
essay cud repeat also.
take care
Regards,
Aamir.

raf
05-03-2006, 08:29 PM
the query to get a random row is quite simple:

SELECT bla, bla2 FROM your_table ORDER BY RAND() LIMIT 1.

but you'll need something extra so that this random selection is only run once every day.

2 option:
- using a CRON that will run this query daily, and that will store the primarey key of the selected essay somewhere in a table or file. then on each pageload, use that PK.
- store the PK in the db/file together with the date and check on each pageload if it already is set for today. if not, then run the select and store the PK with the data. If it is already set, just use the PK.

amir
05-04-2006, 07:06 AM
thanx a lot
God bless u.

raf
05-04-2006, 09:06 AM
you're welcome :thumbsup: