Re: how to display photos of the day?

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

 



At 6:33 PM +0800 1/29/08, jeffry s wrote:
sorry if this question sound stupid.
i need a good, simple and efficient function to display lets say photo of
the day.

i have a mysql table contain data about 1000 rows. i want to display any of
the photos randomly
and it is fixed for one day.

anyone know how to write the function that return a fixed table id for the
day?


What I would do is something like this (assuming your table has a column 'filename' in it):

Create a cron job (on windows, I think the command is called 'at'?) that runs this query

	select filename from photo_table order by rand() limit 1

once per day, then copies that file to a predefined location (eg images/pic_of_the_day.jpg).

Then, your web page simply refers to images/pic_of_the_day.jpg. The contents of pic_of_the_day.jpg change every time the cronjob runs (unless you randomly pick the same picture twice; not likely with 1000 rows, but you could include some sort of flag [eg; last used date] to avoid picking the same image twice, or to cycle through all images before reusing them).

This requires one database hit per day, returning one row, so the load is next to nothing.

The cronjob could be written in any language, but since this is a PHP list you'll have to promise to write it in PHP ;)

	steve


--
+--------------- my people are the people of the dessert, ---------------+
| Steve Edberg                                http://pgfsun.ucdavis.edu/ |
| UC Davis Genome Center                            sbedberg@xxxxxxxxxxx |
| Bioinformatics programming/database/sysadmin             (530)754-9127 |
+---------------- said t e lawrence, picking up his fork ----------------+

--
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