Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: timer script to show image..

  1. #1
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default timer script to show image..

    I have been looking for a script like this and cant seem to make one on my own...

    what I need is a script that will change a image depending on the time of day.

    say like from 12am-3pm display image and 3:01pm-11:59pm show image...

    can someone give me a pointer.. and is it possible with php, I dont really want to use javascript for this...

    its a for a website that I am building for a restaruant.. Thanks guys...
    Hey new design new look, goto xudas for personal webdsign help.. (:

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Do a search...

    I've seen this request hundreds of times on this forum. There are scripts laying around. Specfically, try limiting your search to the request a script forum.

  3. #3
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    no the others are so different..

    what I am trying to do is like..
    if($time == $lunch) {
    echo
    }
    if($time == $dinner) {
    echo
    }
    can someone help on how to actually do this.. just a little bump please.... thanks
    Hey new design new look, goto xudas for personal webdsign help.. (:

  4. #4
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Oh I see...

    That's easy enough...

    PHP Code:
    <?

    $time 
    date('H');

    if(
    $time <15) {
        echo 
    "Lunch";
    }
    else {
        echo 
    "Dinner";
    }

    ?>
    This will echo "Lunch" when it's between 0:00 (Midnight) and 15:00 (3:00 PM). Anything over that (i.e. 3:01 to 11:50 or 15:00 to 23:59) echos "Dinner"

  5. The Following User Says Thank You to Medyman For This Useful Post:

    insanemonkey (02-26-2008)

  6. #5
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    thanks.. not very good with learning the greater then signs or less then signs.. still have to learn that part.. but thanks...!!
    Hey new design new look, goto xudas for personal webdsign help.. (:

  7. #6
    Join Date
    Jan 2008
    Posts
    32
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    You could use this to display an image depending on the time.

    PHP Code:
    <?
    $time 
    date('H');
    $images = array(
        
    "Morning" => "morning.jpg",
        
    "Noon" => "daytime.jpg",
        
    "Night" => "nighttime.jpg"
    );
    if(
    $time && $time 10) {
        
    // Morning
        
    $img $imagse["Morning"];
    }
    if(
    $time >= 10 && $time 20) {
        
    // Day time
        
    $img =$images["Noon"];
    }
    else {
        
    // Night time
        
    $img $images["Night"];
    }
    Header("Location: $img");
    ?>

  8. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    <?
    Don't use short opening tags. They've been deprecated and may be disabled on the user's server.
    Header("Location: $img");
    The Location header takes an absolute URI.
    Code:
    <?php
      define('FROM_TIME', 0);
      define('IMAGE_PATH', 1);
      
      $times = array(
        array(0, 'night.png'),
        array(6, 'morning.png),
        array(10, 'day.png'),
        array(20, 'night.png'));
    
      function getFloored($arr, $val) {
        for ($i = 0; $i < count($arr); ++$i)
          if ($arr[$i][0] > $val)
            return $arr[$i - 1][1];
        return false;
      }
    
      $t = getFloored($times, date('H') + 0);
      $img = sprintf('<img src="%s" alt="%s">', $t = $t[IMAGE_PATH], basename($t, '.png'));
    ?>
    Last edited by Twey; 02-28-2008 at 03:14 AM. Reason: Corrections.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #8
    Join Date
    Jan 2008
    Posts
    32
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Quote Originally Posted by Twey View Post
    Don't use short opening tags. They've been deprecated and may be disabled on the user's server.The Location header takes an absolute URI.
    Code:
    <?php
      
      define('FROM_TIME', 0);
      define('IMAGE_PATH', 1);
      
      $times = array(
        array(0, 'night.png'),
        array(6, 'morning.png),
        array(10, 'day.png'),
        array(20, 'night.png'));
    
      function getFloored($arr, $val) {
        for ($i = 0; $i < count($arr); ++$i)
          if ($arr[$i][0] > $val)
            return $arr[$i - 1][1];
        return false;
      }
    
      $img = sprintf('<img src="%s" alt="%s">', $t = getFloored($times, date('H') + 0), basename($t[1], '.png'));
    If you want to nitpick,
    • You didn't close the php tag
    • The short opening tag is only there because I copied from the above script, I didn't write it completely from scratch.
    • The Location header shouldn't take an absolute URI, as I've used it without one and it works fine.
    • Why did you complicate the script so much? It's a simple enough script.

  10. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    If you want to nitpick,
    Nitpick?
    You didn't close the php tag
    You're right. My error.
    The short opening tag is only there because I copied from the above script, I didn't write it completely from scratch.
    You were correcting it, right?
    The Location header shouldn't take an absolute URI, as I've used it without one and it works fine.
    It should take an absolute URI, although most browsers nowadays will accept a relative URI. This is non-standard behaviour, and shouldn't be relied upon.
    Why did you complicate the script so much? It's a simple enough script.
    It's not really more complicated -- I think it's shorter than yours, although I haven't counted the lines. It's just a more elegant way of approaching the problem, with less boilerplate.

  11. #10
    Join Date
    Jan 2008
    Posts
    32
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Quote Originally Posted by Twey View Post
    Nitpick?
    nitpick
    v : be overly critical; criticize minor detai

Bookmarks

Posting Permissions

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