want to change an image every day and not on refresh.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
junedkazi
Forum Newbie
Posts: 1
Joined: Mon Oct 22, 2007 6:13 am

want to change an image every day and not on refresh.

Post by junedkazi »

I have got 4 images and I wnt to change the images every day in a particular order.
After all the images have been repeated once it should go back to the first image.

The number of images might increase in the near future.
so I am looking for a code whigh does not heve to be manipulated again and again.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

What do you have so far?

What have you tried?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: want to change an image every day and not on refresh.

Post by califdon »

junedkazi wrote:I have got 4 images and I wnt to change the images every day in a particular order.
After all the images have been repeated once it should go back to the first image.

The number of images might increase in the near future.
so I am looking for a code whigh does not heve to be manipulated again and again.
One way would be to create a MySQL table with just one record in it, having two fields: a date field and an integer field. In the PHP script that is going to retrieve the images, the image URLs could be loaded into an array (you could even automate that by storing the images, and no other files, in a subdirectory, then reading the files in that directory each time). Then the script could check the database table to see if the stored date equals today's date; if it does, use the integer in the table as the array index; if it doesn't, increment the integer, but if it is greater than the number of images minus one, reset to zero; update the incremented index and today's date in the table.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

How about naming the images 0.jpg, 1.jpg, 2.jpg ... and in your script so something like:

Code: Select all

<a href="path/to/images/<?php echo date('d') % $number_of_images; ?>.jpg"/>
I guess you could also use the day of the year or timestamp/second-in-day. ;)
(#10850)
Post Reply