Results 1 to 7 of 7
  1. #1

    Unhappy Image change with time

    Ive got this php code which changes an image at a specific server time:

    <?php
    $timeOffset = + 0; // in hours, positive or negative
    $nowHour = date("H", time() + (3600 * $timeOffset)) ;

    if ($nowHour >= 16 && $nowHour < 0)
    $message = '<img src="image1">';
    else if ($nowHour >= 0 && $nowHour < 6)
    $message = '<img src="image2">';
    else if ($nowHour >= 6 && $nowHour < 17)
    $message = '<img src="image3">';
    else $message = '<img src="otherimage">';
    print($message);

    ?>
    And it works, i think, but theres a time problem, can anyone help or work out whats wrong?

  2. #2
    Join Date
    Jul 2006
    Location
    Athens
    Posts
    842
    Tokens
    0

    Default

    PHP Code:
    <?php 
    $time  
    date("H"); 
     
    if(
    $time "0" && $time "6") {
    echo 
    "Message 1";
    } elseif(
    $time "6" && $time "12") {
    echo 
    "Message 4";
    } elseif(
    $time "12" && $time "6") {
    echo 
    "Message 4";
    } elseif(
    $time "18" && $time "0") {
    echo 
    "Message 4";
    }
     
    ?>
    That is just something i quickly knocked up but should work fine.
    Last edited by Drompo; 28-08-2007 at 06:06 PM.


  3. #3

    Default

    Doesn't work for me.
    This is really annoying ;[

  4. #4
    Join Date
    Jul 2006
    Location
    Athens
    Posts
    842
    Tokens
    0

    Default

    PHP Code:
    <?php 
    $time 
    date("H");
     
    if(
    $time >= "0" && $time "6") {
    echo 
    "Message 1";
    } elseif(
    $time >= "6" && $time "12") {
    echo 
    "Message 2";
    } elseif(
    $time >= "12" && $time "18") {
    echo 
    "Message 3";
    } elseif(
    $time >= "18" && $time "24") {
    echo 
    "Message 4";
    }
     
    ?>
    Sorry, My Dodgy Code.
    That will work.


  5. #5

    Default

    Thanks so much!
    Can i ask one more thing, if i wanted it to display an image instead of text, what would the code be?

  6. #6
    Join Date
    Jul 2006
    Location
    Athens
    Posts
    842
    Tokens
    0

    Default

    echo "<img src='IMAGEURL'>";


  7. #7

    Default

    Ahh

    I was using " instead of '

    Thanks so much! :]

Posting Permissions

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