joomlavideos Posted August 25, 2009 Report Share Posted August 25, 2009 Hi, I found this cool script that will allow me to change an image based on the time of day and the week. Here is the script itself: ------------------ <?php $h = date('G'); //set variable $h to the hour of the day $d = date('w'); //set variable $d to the day of the week. $year = date('Y'); //set variable $year to the current year //G is the date key for hours in 24 format (not 12), with no leading 0s, like 02. // Adjust 1 hour offset for CST below. $h = $h-1; // MONDAY SCHEDULE if ($d == 1 && $h >= 16 && $h < 17) $img = 'images/onAir.gif'; else if ($d == 1 && $h >= 17 && $h < 16) $img = 'images/offAir.gif'; // TUESDAY SCHEDULE if ($d == 2 && $h >= 16 && $h < 17) $img = 'images/onAir.gif'; else if ($d == 2 && $h >= 17 && $h < 16) $img = 'images/offAir.gif'; // WEDNESDAY SCHEDULE if ($d == 3 && $h >= 16 && $h < 17) $img = 'images/onAir.gif'; else if ($d == 3 && $h >= 17 && $h < 16) $img = 'images/offAir.gif'; // THURSDAY SCHEDULE if ($d == 4 && $h >= 16 && $h < 17) $img = 'images/onAir.gif'; else if ($d == 4 && $h >= 17 && $h < 16) $img = 'images/offAir.gif'; // FRIDAY SCHEDULE if ($d == 5 && $h >= 16 && $h < 17) $img = 'images/onAir.gif'; else if ($d == 5 && $h >= 17 && $h < 16) $img = 'images/offAir.gif'; // SATURDAY SCHEDULE else if ($d == 7 && $h >= 0 && $h < 24) $img = 'images/offAir.gif'; // SATURDAY SCHEDULE else if ($d == 7 && $h >= 0 && $h < 24) $img = 'images/offAir.gif'; ?> basically this is for a radio show - and I have an image I want to display between 4-5pm CST that says "On the Air", and then display "Off the Air" any other time of the day. My question is this: Being that the place where I want this image to load is in a DIV and in an include, where do I load this script? I tried to place the script in the div itself in the include, then I tried create a separate include with a php extension and insert it within the original include itself (nested - I know probably not a good idea), but I am not seeing anything in either case. Would anyone have an idea on how I can modify this to accommodate my wishes? Thanks! JJ Quote Link to comment Share on other sites More sharing options...
bishwadeep Posted August 25, 2009 Report Share Posted August 25, 2009 Hi joomlavideos, Can you try this script. I have assumed that the radio will be offair on saturday and sunday. Regarding the time this script takes the server time so you might need to compare the server time and your local time. <?php $d=date("l"); $h=date("h"); //offline for saturday and sunday if($d=="Saturday" or $d=="Sunday"){ $img="images/offAir.gif"; //offline image. }else{ if($h >= 4 and $h < 5){ $img="images/onAir.gif"; //for online image. }else{ $img="images/offAir.gif";//offline after 5pm and before 4pm } } ?> Quote Link to comment Share on other sites More sharing options...
lm Posted August 25, 2009 Report Share Posted August 25, 2009 start with creating test file, say test.php - copy paste this script into it as it is - just to see if this script working. Check also paths to the images - they should be in "images" folder as it stand in the script: images/offAir.gif. then use this script as include in any div as you were doing but again, check if paths to the images are correct or rather use absolute paths while testing. Quote Link to comment Share on other sites More sharing options...
joomlavideos Posted August 25, 2009 Author Report Share Posted August 25, 2009 Hi joomlavideos,Can you try this script. I have assumed that the radio will be offair on saturday and sunday. Regarding the time this script takes the server time so you might need to compare the server time and your local time. <?php $d=date("l"); $h=date("h"); //offline for saturday and sunday if($d=="Saturday" or $d=="Sunday"){ $img="images/offAir.gif"; //offline image. }else{ if($h >= 4 and $h < 5){ $img="images/onAir.gif"; //for online image. }else{ $img="images/offAir.gif";//offline after 5pm and before 4pm } } ?> Thanks for the reply. I inserted your script in the include and tested in the browser. But what I got was the code showing on the web page. Am I supposed to place the actual PHP code somewhere else, and then use the in the div? Thanks! Quote Link to comment Share on other sites More sharing options...
joomlavideos Posted August 25, 2009 Author Report Share Posted August 25, 2009 <?php $h = date('G'); //set variable $h to the hour of the day $d = date('w'); //set variable $d to the day of the week. $year = date('Y'); //set variable $year to the current year //G is the date key for hours in 24 format (not 12), with no leading 0s, like 02. // Adjust 1 hour offset for CST below. $h = $h-1; // MONDAY SCHEDULE if ($d == 1 && $h >= 16 && $h < 17) $img = 'http://ourclient.info/WSS3/images/onAir.gif'; else if ($d == 1 && $h >= 17 && $h < 16) $img = 'http://ourclient.info/WSS3/images/offAir.gif'; // TUESDAY SCHEDULE if ($d == 2 && $h >= 16 && $h < 17) $img = 'http://ourclient.info/WSS3/images/onAir.gif'; else if ($d == 2 && $h >= 17 && $h < 16) $img = 'http://ourclient.info/WSS3/images/offAir.gif'; // WEDNESDAY SCHEDULE if ($d == 3 && $h >= 16 && $h < 17) $img = 'http://ourclient.info/WSS3/images/onAir.gif'; else if ($d == 3 && $h >= 17 && $h < 16) $img = 'http://ourclient.info/WSS3/images/offAir.gif'; // THURSDAY SCHEDULE if ($d == 4 && $h >= 16 && $h < 17) $img = 'http://ourclient.info/WSS3/images/onAir.gif'; else if ($d == 4 && $h >= 17 && $h < 16) $img = 'http://ourclient.info/WSS3/images/offAir.gif'; // FRIDAY SCHEDULE if ($d == 5 && $h >= 16 && $h < 17) $img = 'http://ourclient.info/WSS3/images/onAir.gif'; else if ($d == 5 && $h >= 17 && $h < 16) $img = 'http://ourclient.info/WSS3/images/offAir.gif'; // SATURDAY SCHEDULE else if ($d == 6 && $h >= 0 && $h < 24) $img = 'http://ourclient.info/WSS3/images/offAir.gif'; // SUNDAY SCHEDULE else if ($d == 7 && $h >= 0 && $h < 24) $img = 'http://ourclient.info/WSS3/images/offAir.gif'; ?> Quote Link to comment Share on other sites More sharing options...
lm Posted August 25, 2009 Report Share Posted August 25, 2009 check php syntax in this line: there should be "php" added after first ? mark me thinking. Quote Link to comment Share on other sites More sharing options...
Guest vikash Posted August 26, 2009 Report Share Posted August 26, 2009 hi, replace this line with Quote Link to comment Share on other sites More sharing options...
lm Posted August 26, 2009 Report Share Posted August 26, 2009 so this is your working script : <?php$d=date("l"); $h=date("h"); //offline for saturday and sunday if($d=="Saturday" or $d=="Sunday"){ $img="imagepath"; //offline image. }else{ if($h >= 4 and $h $img="imagepath"; //for online image. }else{ $img="imagepath";//offline after 5pm and before 4pm } } ?> Quote Link to comment Share on other sites More sharing options...
bishwadeep Posted August 27, 2009 Report Share Posted August 27, 2009 yes im is right. The short tag value might be off in your php ini settings. That is why the tag is displaying in the browser. <?php echo $img;?> will help in that case. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.