Re: Joke of the day problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 3/8/2007 05:30 AM, Delta Storm wrote:
I need a script that will take data from MySQL database and display one row each day.
...
The database retrieving mechanism is of course clear but I really dont know how to do a 24h delay before the next row is displayed.


Hi Delta,

You haven't stated whether you want the database retrieval to be random (although constant for one day) or sequential. If sequential, I'd think you could just use the day number as an offset into the recordset:

        SELECT Joke FROM Jokes LIMIT $iDay, 1

where $iDay is the current offset of today in the year -- in PHP that's date('z').
http://php.net/date

All you'd need is 356 jokes to guarantee a different one each day.

However, it sounds like you want the joke to be extracted at random each day. I'd like to question this approach, as it will undoubtedly output some of the same jokes more than once in a given year... unless you build in a way of preventing duplicates... or unless your client doesn't care if that happens...

What I would suggest is to allow the software to extract jokes sequentially using "LIMIT $iDay, 1" and generate the database of jokes, in whatever order, once a year. Rather than randomly selecting a record each time you pull a joke from the database, you apply any randomness you want once a year when the database is assembled.

Regards,

Paul
__________________________

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux