I need to display a link at a very specific time using PHP. The php for the WLSG schedule works and that’s because it’s a pretty simple program that starts on the hour and ends on the hour.
My dilemma is that I have another program that starts at (server time) 23:45 on Sunday and ends at 0:00 on Monday. I’m having issues with it displaying the entire day regardless of the times I’ve entered here. I’ve been tinkering with it for the last hour and just cannot figure out what I’m missing.
Here is my php code:
<?php
// Variables
$h = date('G');
$m = date('i');
$d = date('l');
//WLSG Schedule
if ($d != 'Monday') $wlsgDayToggle = 'radio-offline';
if ($h > 0) $wlsgTimeToggle = 'radio-online';
if ($h < 1) $wlsgTimeToggle = 'radio-online';
else $wlsgTimeToggle = 'radio-offline';
//UCR Schedule
if ($d != 'Sunday') $ucrDayToggle = 'radio-offline';
if ($h > 23) $ucrTimeToggle = 'radio-online';
if ($m > 40) $ucrTimeToggle = 'radio-online';
if ($m < 59) $ucrTimeToggle = 'radio-online';
else $ucrTimeToggle = 'radio-offline';
?>
Here is the HTML:
<div id="radio-online">
<p><a class="<?php echo $wlsgDayToggle; ?> <?php echo $wlsgTimeToggle; ?>" href="#" title="Online! Listen Now!" target="_blank">Online! Listen Now!</a></p>
<p><a class="<?php echo $ucrDayToggle; ?> <?php echo $ucrTimeToggle; ?>" href="#" title="Online! Listen Now!" target="_blank">Online! Listen Now!</a></p>
</div>
And the CSS:
a.radio-online { display: inline; }
a.radio-offline { display: none; }
If you want to “string together the if statements”, as you have just told me in your last comment, you must do (for example):
But, if you need to display the link between 11:45pm and 11:59pm on Sunday, you could do something simpler: