Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

shows each day another image

Status
Not open for further replies.

kaul1jos

Technical User
Jan 5, 2001
76
NL
I want some help on my problem.

I know how to display an image on a html page, but how can I display just one image a day.

e.g.
Today I show a picture of a dog
Tomorroy I show a picture of a cat
The day after tomorrow I show a picture of a horse
etc
And when all pictures have seen after a week or 14 days we start the cyclus over and over again.

The pages can be written in html / php / javascript
 
If you do this with client-side Javascript, you will be at the mercy of the date on the client's computer. While this is usually fairly accurate, it's not something to be counted on. I'd recommend handling this with server side scripting instead.

I'd put the graphics in an array, then calculate the day of the year and then use modulo division by 14 to select the photo for the day. While this isn't accurate at the year change, it's good for the rest of the year. Otherwise, you can get the absolute time from Jan 1, 1980, and calculate an absolute day from that and do the same modulo division to select the graphic to display.
 
Hi,
Here is a client-side solution:
You can name the files from 0 to 6: 0.jpg, 1.jpg, 2.jpg, ..., 6.jpg or you can go for the array option, but let's stick to the first solution now.

Now, your javascript should look like this:

<script language=&quot;javascript&quot;>
<!--
var date = new Date();
var d = date.getDay();
document.write(&quot;<img src='images/&quot; + d + &quot;.jpg'>&quot;);
//-->
</script>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top