Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Radio Station site

Posted by bschultz (bschultz), 18 July 2004
Hi Everyone!

I've got a couple questions.  I work at a radio station (news and talk), and I'd like to simplify my life a little.  I've written a php script to display "who is on the air now".  It's only based on time of day and day of the week.  We have lots of "special" programming that changes from week to week (mainly sporting events) that I REALLY don't want to have to change in the php script every week.  Would a mysql db that has the programming for the month work as well as I'd like it to...(I THINK it will, but I haven't used many of the "extras" in mysql)?

On a somewhat related topic...we are able to stream our audio online for local programming only.  If we get the show from a syndicated source, we can't stream it.  Programming the streaming software as to when it can be streamed and when it can't be streamed is a PAIN IN THE BUTT!  I'd like to disable the url to the stream if we can't stream that program.  Is that possible in mysql (or any other language)

I've only used php and mysql (a little)...so I'm sure that what I'm asking is possible...I just don't know where to look and what language to look at.

Thanks for the help.

Brian

Posted by admin (Graham Ellis), 3 August 2004
Oh yikes - I missed this post so my reply is a little tardy. Most have slipped through the net when I was in Rome for a few days. Hopefully "better late than never".

I would think you can do most of what you want with date specific PHP scripts - simply use functions like time or date to work out when the script is bieng run, and then adjust the output accordingly. A MySQL database might work well for you, or you might find it easier simply to maintain a text file into which you place all the times / dates / events you want on the site. We use such a scheme for copyright and course dates througout out own site so that we're not advertising events that are long-passed, even if the data remains on the server  

On the streaming question, you can't really "disable" a URL - well - I suppose you can, but you don't want to as people will get an ugly "403" or "404" depending on how you do it. Better to replace the page with a PHP script that refreshes to the audio feed, or comes up with an explanation as to why no feed is available.  I guess you can be really clever and have the PHP script turn the feed on or off each time it's run, thus ensuring that anyone who directly bookmarks the feed will find it's turned off pretty quickly (by another user) when you move from local to syndicated programming, and vice versa.

You ask what language - PHP!!!!!!   You know some PHP already and it can do an excellent job for you. No point in learning an alternative.

Posted by bschultz (bschultz), 3 August 2004
thanks, Graham...

You're right, better late than never.  I've already implamented a php script but I'm still leaning toward a database for ease of changing what needs to be changed from week to week.

Thanks for solidifying my choice (and for the email!).

Brian

Posted by bschultz (bschultz), 14 September 2004
It's been a while since I've had any time to work on this.  I still don't like how many steps there are for changing a program from week to week.  Here's a snipet of code for one show

Code:
<?php


$current_day = getdate();

//Remember 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday
//6=Saturday, 0=Sunday


if($current_day["wday"] >= 1 && $current_day["wday"] <= 5) { //Monday through Friday

//Remember the following   0=midnight, 23=11pm

if($current_day["hours"] >= 0 && $current_day["hours"] <= 4) {

echo "<table width='100%' border='0' cellspacing='2' cellpadding='2'>
<div align='center'><font color='#000000' size='2'><strong>On Air Now</strong><br>
 Coast To Coast <br>
 With George Noory</font><br>
 <a href='http://www.coasttocoastam.com/'>
 <img src='images/hosts/noory.jpg' width='106' height='150' border='0'></a>
 <br>
 <font color='#000000' size='2'>Monday - Friday<br>
 mid-5am</font></div>
 </tr>
</table>";  }

}

// end of time block


I have that for each show, for each day of the week.  The script is 800 lines long!  I'll admint that it's been so long since I've dealt with php, could you point me in the right direction for using a text file?  I think that would be a much simplified solution than a database.

Thanks.

Brian

Posted by admin (Graham Ellis), 14 September 2004
A database is usually preferable as it would lead you to a file that can be maintained (and have its integrity maintained) by some standard applications such as phpmyadmin - however, you have the special case of a piece of code and data file that's going to be looked after by just you.

I happen to be running a PHP course in about 4 hours (see http://www.wellho.net/course/phfull.html - sorry about the ad), so I've take the opportunity to get into gear by writing an example program - I cut and pasted your code and added a data file containing a program listing.   Here's the program:

Code:
<html>
<head><title>Demo to show what Program's on</title></head>
<body bgcolor=white><h1>Program demo</h1>
Looks at a data file and tells you what's on - a PHP demo<hr>
<?php
$current_day = getdate();
print "It is day $current_day[wday] and hour $current_day[hours]<br>";
$fh = fopen("bdata","r");
$have = 0;

while ($prog = fgetcsv($fh,2000)) {
       list ($startday,$endday) = explode("-",$prog[0]);
       list ($starthour,$endhour) = explode("-",$prog[1]);

       if($current_day["wday"] >= $startday && $current_day["wday"] <= $endday) {
       if($current_day["hours"] >= $starthour && $current_day["hours"] <= $endhour) {

               print "Current program is <b>$prog[2]</b> with <b>$prog[3]</b>";
               $have = 1;
               break;

       }}
}
if ($have == 0) print "Current program not in database, or we're off air";
?>
<hr>
<a href=http://www.wellho.net>Well House Consultants</a>, <?php print(date("Y")); ?>
<?php include ("demolinks.inc"); ?>
</body>
</html>


and here's the datafile that goes with it

Code:
1-5,0-4,"Coast to Coast","George Noory"
1-5,5-7,"Wake up Breakfast","John Doe"
1-4,8-11,"You slept in and it's midweek","Samantha Smith"
5-5,8-11,"Weekend starts here","Samantha Smith"
0-6,12-18,"The afternoon show","P. M. Terence"
0-0,0-11,"Sunday Snooze","A Guest presenter"
6-6,0-11,"Waken with Sport","M. Jones and the Olympic team"
0-6,19-20,"The ride home","The staff of DC Rapid Transit"
1-5,21-23,"You should be sleeping","No presenter - just music!"


I've briefly tested this - it's on line at http://www.wellho.net/demo/radio.php4 and the sample data is in the same directory.

Please feel free to use this as a basis / copy / update / modify / extend for your own use.  Beware that it is VERY easy to get the data wrong in the format adopted, and that you need to consider time zone issues (our server for this demo is in California) ... that's why I've had my demo tell you what it thinks the time is for when you try it out.

Posted by bschultz (bschultz), 14 September 2004
Thanks for the code, Graham.  Just so that I'm sure I follow what you've done:

Quote:
1-5,0-4,"Coast to Coast","George Noory"


1-5 is the days of the week...0-4 is the hours that the show is on?  Is that right?

I don't need to worry about time zones, since the server is right down the hall from my office.  

Thanks again, Graham.

Brian

Posted by admin (Graham Ellis), 14 September 2004
Yep, you've read that right "1-5,0-4" is Monday to Friday, midnight to 04:59 a.m.  

Posted by bschultz (bschultz), 14 September 2004
thanks, Graham.  I'll tweak the code to suit my needs, and I'll repost the code for others.

Thanks again!  I'm always amazed how helpful you are!

Posted by bschultz (bschultz), 27 April 2005
I just realized that I never posted my code for this.  I did, in the end, decide on a database for ease of editing.

Code:
<?php
$current_day = getdate();

$connection = mysql_connect ("localhost", "username", "password");
if ($connection == false){
 echo mysql_errno().": ".mysql_error()."<BR>";
 exit;
}

$query = "select * from rotate WHERE day='$current_day[wday]' and time='$current_day[hours]'";
$result = mysql_db_query ("kkbj", $query);

if ($result){
 echo "";
 echo "";

 $numOfRows = mysql_num_rows ($result);
 for ($i = 0; $i < $numOfRows; $i++){

$day=mysql_result($result,$i,"day");
$time=mysql_result($result,$i,"time");
$show=mysql_result($result,$i,"show");
$host=mysql_result($result,$i,"host");
$pic=mysql_result($result,$i,"pic");
$link=mysql_result($result,$i,"link");
$days=mysql_result($result,$i,"days");
$hour=mysql_result($result,$i,"hour");
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>
   <td><div align="center"><strong>On Air Now</font><br>
       </strong>
       <?php
echo "$show <br>";
echo "$host <br>";
echo "$link";
echo "$pic <br>";
echo "$days <br>";
echo "$hour";
?>
       </div></td>
 </tr>
</table>

<?php
}

 echo "";
}
else{
 echo mysql_errno().": ".mysql_error()."<BR>";
}


?>
</body>

</html>


As a note, $days and $hours are the days and hours the show is on the air...it just gets echoed onto the page.  If you want to see it in action, visit http://kkbjam.com

Thanks again, Graham

Brian



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho