Click to See Complete Forum and Search --> : Radio Station On Air Script
bonneyabweb2
08-25-2005, 11:41 AM
Don't know if anyone's ever come across something like this, but I need a way to display a bit of HTML with info of who is on air at certain times of day (ie. every hour). I currently manage this with Javascript (see www.offthechartradio.co.uk), but for the new site i'm designing for several reasons this won't work.
Ideally i'd like the index.php file to work out the current time and then call up the correct bit of code for that time from another file.
Hopefully someone's come across one of these in the past, any help much appreciated but bear in mind i'm a complete PHP novice :)
Wart_Hog
08-25-2005, 03:40 PM
Hi,
This solution might work for you. You start by storing all of your information in an array: KEY = 'hour of day' and VALUE = 'dj name'. Then you get the current hour with the date() function. I put 'G'
inside for the formatting string -- this will return the hour of the day in 24 hour time without leading zeros. Next, loop through the array and see if any keys match the current time. If there is a match, print the dj name.
<?
// set up an array with hours of the day as KEY and dj names as VALUE
$times=
array(
/* 12:00pm */ '12' => 'Jack the Ripper',
/* 1:00pm */ '13' => 'Barney the Dinosaur',
/* 2:00pm */ '14' => 'Pinky McPinkerson',
/* 3:00pm */ '15' => 'Johny Appleseed'
);
// Get current server time as military time (hour only, no leading zeros)
$time_now = date('G');
// Loop through the array and find a match for $time-now
foreach($times as $hour => $dj){
if($hour == $time_now){
print 'The current DJ is: '.$dj;
}
}
?>
I hope this is helpfull,
-Mike
bonneyabweb2
08-25-2005, 03:48 PM
Looks great, will have a go tomorrow, thanks!
bonneyabweb2
09-01-2005, 01:26 PM
Ok, that works great, but what i'd now like to be able to do is add some SSI (if possible). I've called this file nowplaying.php:
<?
// set up an array with hours of the day as KEY and dj names as VALUE
$times=
array(
/* 12:00pm */ '12' => 'Jack the Ripper',
/* 1:00pm */ '13' => 'Barney the Dinosaur',
/* 2:00pm */ '14' => 'Pinky McPinkerson',
/* 3:00pm */ '15' => 'Johny Appleseed',
/* 4:00pm */ '16' => '',
/* 5:00pm */ '17' => '',
/* 6:00pm */ '18' => '',
/* 7:00pm */ '19' => '',
/* 8:00pm */ '20' => '',
/* 9:00pm */ '21' => '',
/* 10:00pm */ '22' => '',
/* 11:00pm */ '23' => '',
/* 00:00am */ '00' => ''
);
// Get current server time as military time (hour only, no leading zeros)
$time_now = date('G');
// Loop through the array and find a match for $time-now
foreach($times as $hour => $nowplaying){
if($hour == $time_now){
print $nowplaying;
}
}
?>
In my index.shtml file this is brought in using: <!--#include file="nowplaying.php" -->
The trouble I have is there is another PHP file (selectnowplaying.php) which works out the song that is now playing from a database. What I want to be able to do is only display this now playing information at certain times of day on the index.shtml page. I've tried putting <!--#include virtual="selectnowplaying.php" --> in place of the DJ names in the code above but this just produced a blank result instead of the expected now playing information. Any ideas?
Thanks
Andy