View Full Version : change picture after given time
mukkii
02-12-2010, 07:11 PM
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.
bluewalrus
02-13-2010, 10:28 PM
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?
mukkii
02-13-2010, 11:21 PM
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/
CustomPowerDesigns
02-14-2010, 03:44 AM
<?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.
mukkii
02-14-2010, 01:41 PM
just to be clear, 15.00pm is just an example.
bluewalrus
02-14-2010, 05:12 PM
Yea, just change that value or make the value a variable
<?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.
Schmoopy
02-15-2010, 06:54 AM
Just to fix the parse error:
<?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.
mukkii
02-19-2010, 07:06 PM
ok, thanks. But how to translate this now into Smarty?
djr33
02-19-2010, 07:31 PM
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
$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.
propmaster
06-28-2010, 07:23 PM
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
bluewalrus
06-28-2010, 07:33 PM
Yes just change the hours to a date...
http://php.net/manual/en/function.date.php
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.