how to display photos of the day?

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


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-29-2008
jeffry s
 
Posts: n/a
Default how to display photos of the day?

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?

Reply With Quote
  #2 (permalink)  
Old 01-29-2008
Zoltán Németh
 
Posts: n/a
Default Re: [PHP] how to display photos of 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
Reply With Quote
  #3 (permalink)  
Old 01-29-2008
Steve Edberg
 
Posts: n/a
Default Re: [PHP] how to display photos of the day?

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 ----------------+
Reply With Quote
  #4 (permalink)  
Old 01-29-2008
Paul Scott
 
Posts: n/a
Default Re: [PHP] how to display photos of the day?


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

Reply With Quote
  #5 (permalink)  
Old 01-29-2008
tedd
 
Posts: n/a
Default Re: [PHP] how to display photos of the day?

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
Reply With Quote
  #6 (permalink)  
Old 01-29-2008
Per Jessen
 
Posts: n/a
Default Re: [PHP] how to display photos of the day?

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:05 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0