I Have an on air script. I want to show who now on air. I have this script:
<?php
putenv("TZ=Europe/Amsterdam");
$h = date('G');
$d = date('w');
// Sunday
if ($d == 0 && $h >= 0 && $h < 9) { // Show Runs From Midnight til 6am
$djname = 'Kick Radio'; //DJ Name
$show = 'Kick Non Stop'; // Show description
}
elseif ($d == 0 && $h >= 0 && $h < 10) { // Show Runs From Midnight til 6am
$djname = 'Kick Radio'; //DJ Name
$show = 'Sunday Morning Songs'; // Show description
}
elseif ($d == 0 && $h >= 10 && $h < 0) { // Show Runs From Midnight til 6am
$djname = 'Kick Radio'; //DJ Name
$show = 'Kick Non Stop'; // Show description
}
// Monday
if ($d == 1 && $h >= 0 && $h < 0) { // Show Runs From Midnight til 6am
$djname = 'Kick Radio'; //DJ Name
$show = 'Kick Non Stop'; // Show description
}
echo '<h3>'.$show.'</h3>';
But it didn't show something. Only the <h3>
tags. What's wrong with this code?
The problem is you give a chance to Sun $d == 0
and Mon $d == 1
only. You need conditions for other days of week too
Hours $h can't be >= 0
& < 0
same time. So your 3rd and 4th conditions are impossible
Start with following code
if ($d == 0 && $h >= 0 && $h <= 6) {
// Sunday midnight - 6 a.m.
}
elseif ($d == 0) {
// remaining hours of Sunday
}