This is a discussion on how to display photos of the day? within the PHP General forums, part of the PHP Programming Forums category; sorry if this question sound stupid. i need a good, simple and efficient function to display lets say photo of ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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? |
|
|||
|
2008. 01. 29, kedd keltezéssel 18.33-kor jeffry s ezt Ã*rta:
> 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? a good article on the subject: http://www.titov.net/2005/09/21/do-n...ws-from-table/ greets Zoltán Németh |
|
|||
|
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@ucdavis.edu | | Bioinformatics programming/database/sysadmin (530)754-9127 | +---------------- said t e lawrence, picking up his fork ----------------+ |
|
|||
|
On Tue, 2008-01-29 at 18:33 +0800, jeffry s wrote: > 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. > MySQL has a rand() function, so you could bomb that off as a select once a day on cron or something, or you could do a regular select and array_rand() it in PHP. --Paul All Email originating from UWC is covered by disclaimer http://www.uwc.ac.za/portal/public/p...disclaimer.htm |
|
|||
|
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? jeffry: Simple enough:. 1. Figure out what day it is. 2. Pull a random image from the database if that date has changed. If it were me, I would create a simple field in the database that would have todays date (day of the year) in it. Then my script would check date(z) with that field. If the value is different, then I would replace that value with the new value and then change the picture accordingly by using the rand() function. Cheers, tedd PS: date(z) produces the day of the year (1-365) -- ------- http://sperling.com http://ancientstones.com http://earthstones.com |
|
|||
|
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. I use apache for that sort of thing: ..htaccess: RewriteEngine on RewriteCond todaysphoto.jpeg !-s RewriteRule picktodaysphoto.php "picktodaysphoto.php" selects the photo of the day, writes it as 'todaysphoto.jpeg', and then redirects to it. 'todaysphoto.jpeg' is then deleted once a day by cron. /Per Jessen, Zürich |