SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Zealot PenGwnFistOfFury's Avatar
    Join Date
    Feb 2005
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    image changing script

    I am looking for a script that changes, images based on the time on the server. So at 12:00 its imageA then at 3:30 its imageB and so on. has anyone seen or used a script like this?

  2. #2
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Which serverside language can you use? php, asp or something else - I doubt Javascript would be able to handle this? If you know which serverside language you can ask a mod to move this thread in the appropriate forum where more people would be able to help you out.
    Dan G
    Marketing Strategist & Consultant

  3. #3
    SitePoint Zealot PenGwnFistOfFury's Avatar
    Join Date
    Feb 2005
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    php

  4. #4
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ask a mod to move this thread in the appropriate forum where more people would be able to help you out
    The appropriate Forum would be in this case: PHP

    Or you might be allowed to ask this question here (never visit this subforum of Sitepoint): Scripts and Online Services
    Dan G
    Marketing Strategist & Consultant

  5. #5
    SitePoint Zealot PenGwnFistOfFury's Avatar
    Join Date
    Feb 2005
    Posts
    148
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ^^ I guess thats what I get for skimming and not reading.

    Could a mod move this thread to the php section.

  6. #6
    Night Elf silver trophybronze trophy Varelse's Avatar
    Join Date
    Mar 2005
    Location
    eu
    Posts
    5,967
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    FreelanceDaddy - freelancer's personal advisor
    █ Guide and advice for freelancers starting their career
    █ Over 1000 projects posted on freelance markets every day
    █ One-stop resource for online freelancing

  7. #7
    SitePoint Addict
    Join Date
    Jul 2006
    Location
    Kansas City, MO
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First you need to decide how to format the time. Let's keep it simple and do 0000-2359 (midnight through 11:59pm). So we'll get the current time in that format:

    PHP Code:
    $currentTime date('Hi'); 
    Now that we have $currentTime as a string of '0000' - '2359' we can pick an image. Best and easiest way would be to create an array of starting times for an image to appear (with the ending time being the next startTime). Here's what I mean

    PHP Code:
    $imageTimes = array(
    '0000' => 'image1.gif',
    '0330' => 'image2.gif',
    '0700' => 'image3.gif',
    '1700' => 'image4.gif'
    ); 
    Basically that defines 4 images. Midnight to 3:29am is image1, 3:30am to 6:59am is image2, 7:00am to 4:59pm is image3, 5:00pm to 11:59pm is image4. Now all we need to do it iterate through the array and pick the image which our $currentTime falls into:

    PHP Code:
    foreach($imageTimes as $startTime => $imageFilename) {
      if (
    $currentTime >= $startTime)
        
    $displayImage $imageFilename;
      else
        break;
    }

    echo 
    $displayImage
    This goes through each starting time in the images array and compares to the current time. If the current time is equal or greater than, it sets that image as the current. Otherwise (currentTime is before startTime) then it just stops the loop.

    It is important that your array is in increasing order from '0000' to '2359'

  8. #8
    SitePoint Zealot
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or....

    The ojective is to create a method of displaying different images at different times of the day.
    For the purposes of this example, we are presuming the following:

    1. Display a different image each hour of the day (will be
    using military time - 1300 = 1:00PM)
    (ie midnite to 1AM is image 1; 1 AM to 2 AM is image 2 etc)

    2. image data may be gathered into an array via (a) database;
    (b) perusing an image folder; (c) hard coding

    Code:
    <?PHP
    ########################
    #	 Get the array elements
    ########################
    
    $array_of_image_files = array('image00.jpg','image01.jpg','image02.jpg','image03.jpg','image04.jpg','image05.jpg','image06.jpg','image07.jpg','image08.jpg','image09.jpg','image10.jpg','image11.jpg','image12.jpg','image13.jpg','image14.jpg','image15.jpg','image16.jpg','image17.jpg','image18.jpg','image19.jpg','image20.jpg','image21.jpg','image22.jpg','image23.jpg');
    
    ################################
    #	display the image for the current hour
    #           for this example we are only displaying
    #            the image name
    #################################
    
    echo $array_of_image_files[date('H')];
    ?>
    Lite...

  9. #9
    SitePoint Addict
    Join Date
    Jul 2006
    Location
    Kansas City, MO
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Except your method would require 24 images (possibly copies of the same image) and disallow rotation on smaller than 60minute intervals...

  10. #10
    SitePoint Zealot
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    True; however, it all depends upon the goals of the creator.

    Slight adjustments could allow for various time increments as well as 'adjusting' the quantity of images available from the 'pool'

  11. #11
    SitePoint Guru
    Join Date
    Jul 2005
    Location
    Orlando
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    FWIW, this would be very easily done in Javascript.

  12. #12
    SitePoint Addict
    Join Date
    Jul 2006
    Location
    Kansas City, MO
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by UFTimmy
    FWIW, this would be very easily done in Javascript.
    Not really, he said based on the time of the server; not the client.

  13. #13
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by UFTimmy
    FWIW, this would be very easily done in Javascript.
    Quote Originally Posted by c2uk
    Which serverside language can you use? php, asp or something else - I doubt Javascript would be able to handle this? If you know which serverside language you can ask a mod to move this thread in the appropriate forum where more people would be able to help you out.
    Quote Originally Posted by ZareMedia
    Not really, he said based on the time of the server; not the client.
    - Javascript would work only if you want to use the time of the client, not the server.
    Dan G
    Marketing Strategist & Consultant


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
  •