...

View Full Version : show image based on servertime



danielandlisa
03-18-2010, 05:29 PM
Hi, i wonder if somebody can give me a example of how you can show a diffrent image for even and uneven minutes based on servertime
one image shall be shown for even minutes and one for uneven

i understand that is done by getting the time from the server then using a if or else statement but would be good if somebody could show me a example of how its done or send me a link to a tutorial.

/ thanks lisa

Fou-Lu
03-18-2010, 08:29 PM
What is you're langauge version? PHP5 has an easy way:


if (0 == (idate('i') % 2))
{
// even
}
else
{
// odd
}


Otherwise, if you're on PHP4, it would be something like:


$iMinute = (int)(ltrim(date('i'), '0'));
if (0 == ($iMinute % 2))
{
// even
}
else
{
// odd
}


BTW, you realize that this will only produce the initial image, not replace it as time passes correct? PHP has no way of updating a client without a request.

danielandlisa
03-18-2010, 08:34 PM
thanks, it shall not replace the image it shall show one image for even minutes and another for uneven minutes

Fou-Lu
03-18-2010, 08:36 PM
thanks, it shall not replace the image it shall show one image for even minutes and another for uneven minutes

Yeah, but I thought I should clarify. If you sit idle on that page for two minutes, the image won't have changed to the other and then back again, it will be the same image as originally loaded. If you want timed events, you need to use javascript for that.

danielandlisa
03-18-2010, 09:21 PM
ok thanks alot, can you show a example with the srcs to the images specified
im not sure how i shall do that can i echo out the two images?
using php5

Fou-Lu
03-18-2010, 09:46 PM
if (0 == (idate('i') % 2))
{
print '<img src="/path/to/even/image.jpg" alt="" />';
}
else
{
print '<img src="/path/to/odd/image.jpg" alt="" />';
}

danielandlisa
03-18-2010, 09:53 PM
thanks alot :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum