kanal1 Posted June 14, 2009 Share Posted June 14, 2009 Hi! I'm completely new to PHP and I have problems with a script which is supposed to change a image on a certain time. I'm getting it to change as supposed to on the hour, but I have problems putting in the minutes to get the image to change for example at 21.30, 22.45 and 22.10, and not on 21, 22, 23 etc. It works like this: if ($d == 1 && $h >= 0 && $h < 1) $img = 'images/onair_mark.png'; if ($d == 1 && $h >= 1 && $h < 2) $img = 'images/onair_gmp.png'; if ($d == 1 && $h >= 2 && $h < 12) $img = 'images/offair1.png'; if ($d == 1 && $h >= 12 && $h < 14) $img = 'images/onair_slips.png'; if ($d == 1 && $h >= 14 && $h < 21) $img = 'images/offair2.png'; if ($d == 1 && $h >= 21 && $h < 0) $img = 'images/onair_bergtatt.png'; but I haven't figured out how to put minutes into this in a correct way? Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/162142-problem-with-minutes/ Share on other sites More sharing options...
wildteen88 Posted June 14, 2009 Share Posted June 14, 2009 I assume the variable named $h holds the current hour. How are you currently working out the hour? Quote Link to comment https://forums.phpfreaks.com/topic/162142-problem-with-minutes/#findComment-855592 Share on other sites More sharing options...
PFMaBiSmAd Posted June 14, 2009 Share Posted June 14, 2009 If you use a string that has a fixed format 'HH:MM' (with leading zeros) you can directly compare them as long as the values on both sides of the comparison have the exact same format and the fields in the format are ordered left-right from MSD (Most Significant Digit) to LSD (Least Significant Digit), which for an hour/minute would be HH:MM. Quote Link to comment https://forums.phpfreaks.com/topic/162142-problem-with-minutes/#findComment-855597 Share on other sites More sharing options...
kanal1 Posted June 14, 2009 Author Share Posted June 14, 2009 The whole script looks like this: (it's used in a side panel in PHP-Fusion): $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. // MONDAY SCHEDULE if ($d == 1 && $h >= 0 && $h < 1) $img = 'images/onair_mark.png'; if ($d == 1 && $h >= 1 && $h < 2) $img = 'images/onair_gmp.png'; if ($d == 1 && $h >= 2 && $h < 12) $img = 'images/offair1.png'; if ($d == 1 && $h >= 12 && $h < 14) $img = 'images/onair_slips.png'; if ($d == 1 && $h >= 14 && $h < 21) $img = 'images/offair2.png'; if ($d == 1 && $h >= 21 && $h < 22) $img = 'images/onair_blues.png'; if ($d == 1 && $h >= 22 && $h < 23) $img = 'images/onair_toindre.png'; if ($d == 1 && $h >= 23 && $h < 0) $img = 'images/onair_piruetten.png'; // TUESDAY SCHEDULE if ($d == 2 && $h >= 0 && $h < 1) $img = 'images/onair_mark.png'; if ($d == 2 && $h >= 1 && $h < 2) $img = 'images/onair_jukebox.png'; if ($d == 2 && $h >= 2 && $h < 12) $img = 'images/offair1.png'; if ($d == 2 && $h >= 12 && $h < 14) $img = 'images/onair_slips.png'; if ($d == 2 && $h >= 14 && $h < 21) $img = 'images/offair2.png'; if ($d == 2 && $h >= 21 && $h < 0) $img = 'images/onair_bergtatt.png'; // WEDNESDAY SCHEDULE if ($d == 3 && $h >= 0 && $h < 2) $img = 'images/onair_gmp.png'; if ($d == 3 && $h >= 2 && $h < 12) $img = 'images/offair1.png'; if ($d == 3 && $h >= 12 && $h < 14) $img = 'images/onair_slips.png'; if ($d == 3 && $h >= 14 && $h < 21) $img = 'images/offair2.png'; if ($d == 3 && $h >= 21 && $h < 0) $img = 'images/onair_slipskv.png'; // THURSDAY SCHEDULE if ($d == 4 && $h >= 0 && $h < 2) $img = 'images/onair_jukebox.png'; if ($d == 4 && $h >= 2 && $h < 12) $img = 'images/offair1.png'; if ($d == 4 && $h >= 12 && $h < 14) $img = 'images/onair_slips.png'; if ($d == 4 && $h >= 14 && $h < 21) $img = 'images/offair2.png'; if ($d == 4 && $h >= 21 && $h < 0) $img = 'images/onair_mpp.png'; // FRIDAY SCHEDULE if ($d == 5 && $h >= 0 && $h < 2) $img = 'images/onair_jukebox.png'; if ($d == 5 && $h >= 2 && $h < 12) $img = 'images/offair1.png'; if ($d == 5 && $h >= 12 && $h < 14) $img = 'images/onair_slips.png'; if ($d == 5 && $h >= 14 && $h < 21) $img = 'images/offair2.png'; if ($d == 5 && $h >= 21 && $h < 22) $img = 'images/onair.png'; if ($d == 5 && $h >= 22 && $h < 0) $img = 'images/onair_elvis.png'; // SATURDAY SCHEDULE if ($d == 6 && $h >= 0 && $h < 2) $img = 'images/wranglerjukebx.png'; if ($d == 6 && $h >= 2 && $h < 21) $img = 'images/offair2.png'; if ($d == 6 && $h >= 21 && $h < 22) $img = 'images/onair_jukebox.png'; if ($d == 6 && $h >= 22 && $h < 0) $img = 'images/onair_vidarj.png'; // SUNDAY SCHEDULE if ($d == 0 && $h >= 0 && $h < 1) $img = 'images/onair_vidarj.png'; if ($d == 0 && $h >= 1 && $h < 2) $img = 'images/onair_jukebox.png'; if ($d == 0 && $h >= 2 && $h < 21) $img = 'images/offair2.png'; if ($d == 0 && $h >= 21 && $h < 22) $img = 'images/onair_revy.png'; if ($d == 0 && $h >= 22 && $h < 23) $img = 'images/onair.png'; if ($d == 0 && $h >= 23 && $m < 0) $img = 'images/onair_ukar.png'; openside("<center><b>Live på FM 100,6</b></center>"); echo "<center><img src='$img'></center>"; closeside(); It' s probably very simple, but it works! It pulls the time from the server. I'll guess I may have to put this line in the beginning: $i = date('i'); //set variable $i to the minutes of the day I use it on a small website for my local community radio station back home in Norway, and the images changes between when we're on air and off air, and showing what kind of show is currently on air. But some shows starts on for ex. 21.30 or 22.10, and I'm not getting that right! I've tried to just write 21:30 but that didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/162142-problem-with-minutes/#findComment-855648 Share on other sites More sharing options...
PFMaBiSmAd Posted June 14, 2009 Share Posted June 14, 2009 $h = date('H:i'); //set variable $h to the hour and minute of the day if ($d == 1 && $h >= '00:00' && $h < '01:00') $img = 'images/onair_mark.png'; Quote Link to comment https://forums.phpfreaks.com/topic/162142-problem-with-minutes/#findComment-855662 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.