Forum Moderators: coopster
However, I would like to display one single quote for one day, in other word, one quote per day. I was contemplating on having an additional field within the database and based on the current date and the date in the db to show the quote, but that means a lot of work and input of date with every quote.
Please could someone suggest how I can achieve my above goal.
Many thanks for your help. - Melwyn
table quotes - int,date, text
id ¦ date_displayed ¦ quote
Initially, date_displayed is blank or null or '0000-00-00', take your pick
First, make sure there are blank entries to randomize, if not, reset them all to your null date value.
-----> select count(*) from quotes where date_displayed='0000-00-00';
-----> if (! ($count > 0))
------------> update quotes set date_displayed='0000-00-00'
Next, look for anything set for today.
--> select date_displayed, quote from quotes where date_displayed=curdate();
--> if found, display quote
--> if not found,
-----> select id from quotes where date ='0000-00-00' order by rand() limit 1;
-----> update quotes set date_displayed=curdate() where id='$id';
-----> display the quote
The next time it's called, it will find the one matching today's date. Tomorrow, it rolls over to tomorrow's date until they are all used up, and it resets them.