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.
want to change an image every day and not on refresh.
Moderator: General Moderators
Re: want to change an image every day and not on refresh.
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.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.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
How about naming the images 0.jpg, 1.jpg, 2.jpg ... and in your script so something like:
I guess you could also use the day of the year or timestamp/second-in-day. 
Code: Select all
<a href="path/to/images/<?php echo date('d') % $number_of_images; ?>.jpg"/>(#10850)