Jump to content

changing a current image to a different image every 24 hours.


beetle08

Recommended Posts

hi,

im just starting out to understand the different types of  scripting languages so at the moment I don’t know how to script, but im pretty sure what I want is writing in php.

 

the thing that I want is some kind countdown which is from play.com, for a webpage.

countime.png

 

I originally thought it was a proper countdown with the digits changing, but later on I noticed that it was an image changing. If you can have a look at it on the website, play.com, I’d really appreciate it, as I might be wrong.

 

im pretty sure it’s not been created in Javascript, as its not animated. And that you need to refresh the page for the image to change.

My question is, do you also think that they've created this in php, that will replace the existing image (in this case, the 18 days left image) to a different image (like 17 days left image) every 24 hours?

 

Thanks

Link to comment
Share on other sites

here's a sample of what you can do. Simple, quick, dirty, but it should work. If you need help understanding anything, let us know.

<?php
$image_dir = "images/countdown";
$day   = 31;     // Day of the countdown
$month = 12;      // Month of the countdown
$year  = 2010;   // Year of the countdown
$hour  = 23;     // Hour of the day (east coast time)
$event = "New Year's Eve, 2010"; //event
$calculation = ((mktime ($hour,0,0,$month,$day,$year) - time(void))/3600);
$days  = (int)($hours/24);
$image = $image_dir."/$days.gif"; //assuming the image set is gif, and you have them named 1.gif, 2.gif, 3.gif, etc.
echo "<img src='$image'>";
?>

Link to comment
Share on other sites

bad code in my last example. That's what I get for using untested code.

<?php
$image_dir = "images/countdown";
function countdown($month,$day,$year) {
// subtract desired date from current date and give an answer in terms of days
$remain = ceil((mktime(0,0,0,$month,$day,$year) - time()) / 86400);
// show the number of days left
if ($remain > 0) {
	return $remain;
}
// if the event has arrived, say so!
else {
	return "arrived";
}
}
$days = countdown(7,11,2010);
$image = $image_dir."/$days.gif"; //assuming the image set is gif, and you have them named 1.gif, 2.gif, 3.gif,... and one for arrived.gif 
echo "<img src='$image'>"; 
?>

Link to comment
Share on other sites

here's a sample of what you can do. Simple, quick, dirty, but it should work. If you need help understanding anything, let us know.

 

 

thats great, i'll check it out.

 

just one thing, how do you apply this php code into dreamweaver?

 

also where does the code get the curent time from? do i input it into the php, or is it getting the time from the pc clock

,thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.