Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Dec 2009
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts

    show image based on servertime

    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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    What is you're langauge version? PHP5 has an easy way:
    PHP Code:
    if (== (idate('i') % 2))
    {
        
    // even
    }
    else
    {
        
    // odd

    Otherwise, if you're on PHP4, it would be something like:
    PHP Code:
    $iMinute = (int)(ltrim(date('i'), '0'));
    if (
    == ($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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    New Coder
    Join Date
    Dec 2009
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts
    thanks, it shall not replace the image it shall show one image for even minutes and another for uneven minutes

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by danielandlisa View Post
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    New Coder
    Join Date
    Dec 2009
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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
    Last edited by danielandlisa; 03-18-2010 at 09:29 PM.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    PHP Code:
    if (== (idate('i') % 2)) 

        print 
    '<img src="/path/to/even/image.jpg" alt="" />';

    else 

        print 
    '<img src="/path/to/odd/image.jpg" alt="" />';

    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    danielandlisa (03-18-2010)

  • #7
    New Coder
    Join Date
    Dec 2009
    Posts
    24
    Thanks
    2
    Thanked 0 Times in 0 Posts
    thanks alot


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •