Forum Moderators: coopster

Message Too Old, No Replies

Extract and Display the same record for the entire day

Show only one record data per day

         

mvaz

4:31 pm on Feb 19, 2009 (gmt 0)

10+ Year Member



Hi
I have a database full of quotes and I have a scrip that pulls out one random quote and displays the same on the website every time you visit the site.

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

rocknbil

5:09 pm on Feb 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd do this something like this.

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.

mvaz

5:12 pm on Feb 19, 2009 (gmt 0)

10+ Year Member



Thank you, I will try this and keep you posted how it worked. Gotta go now, be back later with result.