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

Thread: change picture after given time

  1. #1
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default change picture after given time

    Hi. I've got the following problem so if anyone can help I would appreciate it.

    I need to set specific time i.e. 15.00 h, and after submitting the chosen time picture A should appear on my homepage and stay there until 15.00 h, and when 15.00 h passes that picture A should be automatically replaced with picture B until new time is chosen again.

    Btw I'm using Smarty.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    No idea what smarty but is 15.00h like 15:00 or 3:00pm or is it 15 hours from a users initial load of your page and after 30.00h is it going back to a or going to c?
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    with 15.00h I meant 3pm

    so as soon as I set the time (ie 15:00:00pm) picture should change form B to A, and after set time passes (15:00:01pm) picture should go back to B.

    the script should be connected to server time in order to work, i suppose.


    Smarty (Template Engine)-> http://www.smarty.net/

  4. #4
    Join Date
    Jan 2010
    Posts
    16
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Code:
          <?php
          /* This sets the $time variable to the current hour in the 24 hour clock format */
          $time = date("H");
          /* Set the $timezone variable to become the current timezone */
          $timezone = date("e");
          /* If the time is less than 1500 hours, show imageA */
          if ($time < "15") {
              echo "code for your image here";
          } else
          /* If the time is greater than or equal to 1500 hours, show imageB*/
          if ($time >= "15" {
              echo "code for your image here or function";
          } else
    
          ?>
    There is your code to set the time. Now you need to get your image from the database and show it in the open code. If you are using just a code hosted on the server then just place the img tags in there, but if you want to display a image that is hosted in your mySQL database you have to connect to it and place the image title.

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

    mukkii (02-19-2010)

  6. #5
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    just to be clear, 15.00pm is just an example.

  7. #6
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Yea, just change that value or make the value a variable

    PHP Code:
        <?php
           $time_hour 
    "15";
          
    /* This sets the $time variable to the current hour in the 24 hour clock format */
          
    $time date("H");
         if (
    $time $time_hour) {
              echo 
    "code for your image here";
          } else
          
    /* If the time is greater than or equal to 1500 hours, show imageB*/
          
    if ($time >= $time_hour {
              echo 
    "code for your image here or function";
          } else
          
    ?>
    I removed the timezone because it wasn't being used you can put it back in if you want to use it. Just change the $time_hour to whatever time you want it to change at.
    Corrections to my coding/thoughts welcome.

  8. The Following User Says Thank You to bluewalrus For This Useful Post:

    mukkii (02-19-2010)

  9. #7
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Just to fix the parse error:

    PHP Code:
        <?php
           $time_hour 
    "15";
          
    /* This sets the $time variable to the current hour in the 24 hour clock format */
          
    $time date("H");
         if (
    $time $time_hour) {
              echo 
    "code for your image here";
          } else
          
    /* If the time is greater than or equal to 1500 hours, show imageB*/
          
    if ($time >= $time_hour) {
              echo 
    "code for your image here or function";
          } else
          
    ?>
    Missing bracket, otherwise, this should work for you.

  10. The Following User Says Thank You to Schmoopy For This Useful Post:

    mukkii (02-19-2010)

  11. #8
    Join Date
    Feb 2010
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    ok, thanks. But how to translate this now into Smarty?

  12. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Edit: This is not working (tested). The problem is that you need to also send out headers and perhaps use another function aside from include. I thought that would be an easy way around it. Realistically the easiest way will just be to figure out how to insert php code into smarty.



    There's another, easy way to do this, than having to use smarty.

    Save the following code as image.php and embed it as html:
    <img src="image.php".......>

    PHP Code:
        <?php
           $time_hour 
    "15";
          
    /* This sets the $time variable to the current hour in the 24 hour clock format */
          
    $time date("H");
         if (
    $time $time_hour) {
              include(
    'image1.jpg'); //the "before" image
          
    } else {
          
    /* the time is greater than or equal to 1500 hours, show imageB*/
              
    include('image2.jpg'); //the "after" image
          
    }
          
    ?>
    Remember: all of these paths must be relative to the correct locations of the files.

    Basically this will use a .php page to serve the correct image based on the time -- the php page itself will "be" the image.


    RE: code above:
    I removed the floating "else" at the end of the code. This might cause a parse error, or at least is not required.
    I also removed the second if: it's the opposite of the first, so that just makes for longer code.
    Last edited by djr33; 02-19-2010 at 06:45 PM.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  13. #10
    Join Date
    Jun 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Same thing only different...

    Is it possible to take this one step further? I hav e been looking for something like this but that would change my header logo for holidays. Kinda like google does. I want to have a series of header logos and select days that they change. Possible?
    Thanks!
    Propmaster

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
  •