Radio station php script

Guys---

Anyone know of a resource where I can find a quick down-and-dirty php script to display an on-air schedule for a radio station? I'd like it to show:

1) Show title and corresponding image
2) Beginning time
3) Ending time

Php noob here, so i can't write one from scratch. Thanks!
billypilgrim32Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ess KayEntrapenuerCommented:
0
billypilgrim32Author Commented:
I just want a simple php script. I think i found one here:

http://thetismedia.webdesignvictoriabc.com/how-to-build-a-dynamic-on-air-now-banner-using-php

i pop this php into a test page on my wordpress site, and i'm unable to display the image. here's my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test php on air script</title>
<?php
$m = date('i');
$hhmm = $h * 100 + $m; //create a variable called $m to define to the minute of the hour. 
$h = date('G'); //create a variable called $h to define to the hour of the day.//
$d = date('w'); //create a variable called $d to the define to the day of the week.//
$year = date('Y'); //create a variable called $year to define to the current year.//
// Note that the hours are in a 24 hour format.//
// Adjust the UTC offset to the timezone your SERVER uses. I'll be demonstrating with UTC-07:00//
$h = $h-7;
if ($d == 1 && $h >= 0 && $h < 1) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host1.jpg'; }
else if ($d == 1 && $hhmm >= 0100 && $hhmm < 0542) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host2.jpg'; }
else if ($d == 1 && $hhmm >= 0542 && $hhmm < 0600) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host2.jpg'; }
else if ($d == 1 && $h >= 6 && $h < 7) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host3.jpg'; }
else if ($d == 1 && $h >= 7 && $h < 8) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host3.jpg'; }
else if ($d == 1 && $h >= 8 && $h < 9) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host4.jpg'; }
else if ($d == 1 && $h >= 9 && $h < 10) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host4.jpg'; }
else if ($d == 1 && $h >= 10 && $h < 11) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host4.jpg'; }
else if ($d == 1 && $h >= 11 && $h < 12) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host5.jpg'; }
else if ($d == 1 && $h >= 12 && $h < 13) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host5.jpg'; }
else if ($d == 1 && $h >= 13 && $h < 14) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host6.jpg'; }
else if ($d == 1 && $h >= 14 && $h < 15) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host6.jpg'; }
//--back to 1--//
else if ($d == 1 && $h >= 15 && $h < 16) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host1.jpg'; }
else if ($d == 1 && $hhmm >= 1600 && $hhmm < 1730) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host1.jpg';}
//--back to 7-10--//
else if ($d == 1 && $hhmm >= 1730 && $hhmm < 1930) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host7.jpg'; }
else if ($d == 1 && $hhmm >= 1930 && $hhmm < 2000) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host8.jpg'; }
else if ($d == 1 && $h >= 20 && $h < 22) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host9.jpg'; }
else if ($d == 1 && $h >= 22 && $h < 23) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host10.jpg'; }
else if ($d == 1 && $h >= 23) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host10.jpg'; }
?>
</head>
<body>
Testing for images...
<br />
<img src="<?php echo $img; ?>">
</body>
</html>

Open in new window

0
Ess KayEntrapenuerCommented:
see if it will work without the wordpress first
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

billypilgrim32Author Commented:
no dice. im just seeing an empty image tag:

<img src="">
0
Ess KayEntrapenuerCommented:
add this somewhere in the end to show what the $d is

if it is not equal to 1 then nothing will show
its most likeley 2 because 1 would be sunday

<?php   echo $d ?>
0
billypilgrim32Author Commented:
after inserting <?php   echo $d ?> it's now displaying a 1.
0
Ess KayEntrapenuerCommented:
lets loop through the other values, one of them is definitely offsetting it


add this where you added the previous statement
<?php
echo "month" & $m & "<BR>";
echo "hhmm" & $hhmm  & "<BR>";
echo "h * 100 + m" & $h * 100 + $m & "<BR>";
echo "h" & $h & "<BR>";
echo "d" & $d & "<BR>";
echo "yr" & $year & "<BR>";
?>
0
billypilgrim32Author Commented:
now i'm getting:

 $000 0
0
Ess KayEntrapenuerCommented:
sorry i was using non-php code paste this instead
im juggling between the 30 or so languages that i know so bear with me

<?php
echo "month $m <BR>";
echo "hhmm $hhmm <BR>";
echo "h $h <BR>";
echo "d $d <BR>";
echo "yr $year <BR>";
?>
0
billypilgrim32Author Commented:
no problem! now i'm getting:

 month 33
hhmm 33
h 5
d 1
yr 2012
0
Ess KayEntrapenuerCommented:
looks like the problem is in these lines

hhmm is only being recognized as two digits instead of four
in lines 16,17, 18

else if ($d == 1 && $hhmm >= 0100 && $hhmm < 0542) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host2.jpg'; }
else if ($d == 1 && $hhmm >= 0542 && $hhmm < 0600) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host2.jpg'; }
else if ($d == 1 && $h >= 6 && $h < 7) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host3.jpg'; }


change the above statements to


else if ($d == 1 &&  $h >= 1 && $h < 6) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host2.jpg'; }
else if ($d == 1 && $h >= 6 && $h < 7) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host3.jpg'; }
0
Ray PaseurCommented:
Sounds like a lot of moving parts to this question.  Maybe it would be better to eat this elephant one byte at a time.  This article will help you understand how to handle DATETIME values in PHP and MySQL.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

Once you have a grip on that you will be able to compare DATETIME strings and string fragments correctly.  HTH, ~Ray
0
billypilgrim32Author Commented:
appreciate the article, Ray, but like i said, i'm a complete novice at php. ill look into it further, but i'm pressed for time to come up with this on-air schedule. Essaykay helped me make it work, but once it ran this function (at about 11pm, CST), it failed to display my image:

 
else if ($d == 1 && $hhmm >= 1730 && $hhmm < 1930) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host7.jpg'; }

Open in new window


so--at least in my feeble mind---i assume the only problem i'm having is figuring out how to make the minute function work.

otherwise, i'm able to understand and manipulate the code to work for me.
0
Ray PaseurCommented:
Sorry, but there really are a lot of moving parts here.  You need to know the timezone for values like $hhmm to make any sense.  It's going to be 1730 somewhere once an hour, and if you're not sure about the timezone, you just don't have a chance.  PHP and MySQL are independent with respect to timezones, and a PHP DATETIME value that is put into a MySQL DATETIME column loses its timezone information, so that must be kept separately.  It's a flaw, but unfortunately that is just the way it works.

Also, a comparison like this may not make any sense because of the way PHP performs loose data typing.
$hhmm >= 1730

Open in new window

It might make more sense to use character strings, as called for in the ISO-8601 standard.
$hhmm >= '1730'

Open in new window

The reason for using character strings goes to the question of getting the string length exactly right and getting the values to compare and sort correctly.

If you're pressed for time and you agree that time is money, it might make sense to hire a professional developer to help you get over this hump.  Then you will have some breathing room and you can decide whether you want to try to learn all that you would need to know to become a professional developer yourself.
0
Ess KayEntrapenuerCommented:
looks like the problem is the $hhmm because it does not read it correctly


basically, what it was supposed to do, is to take the hour and minute and put it in one line
as so 1030, instead there seems to be a problem with the hour part, so how to fix this, you will have to change the line


wherever you see the hhmm change it to the $h (hour)

for example

else if ($d == 1 && $h >= 15 && $h < 16) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host1.jpg'; }
is good

else if ($d == 1 && $hhmm >= 1600 && $hhmm < 1730) { $img = 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host1.jpg';}
//--back to 7-10--//

change
$d == 1 && $hhmm >= 1600 && $hhmm < 1730
to
 $d == 1 && $h >= 16&& $h < 17

then do the same with the next ones increments of one hour or two hours
0
Ess KayEntrapenuerCommented:
PS: Ray_Paseur, since php is processed on the server and not on the client, the timezone is not an issue, though given that the timezone of the actual server is not in your correct location, you might want to change the times above accordingly
0
Ray PaseurCommented:
See http://www.laprbass.com/RAY_temp_billypilgrim32.php and use View Source.
<?php // RAY_temp_billypilgrim32.php
error_reporting(E_ALL);


// SET THE CORRECT TIMEZONE
date_default_timezone_set('America/Chicago');


// A FUNCTION TO RETURN THE IMAGE URL BASED ON A GIVEN TIME
function imageUrl($hhmm='now')
{

    // DEFINE A PROGRAM CLASS
    if (!class_exists('Program'))
    {
        Class Program
        {
            public function __construct
            ( $a // START TIME
            , $z // END TIME
            , $i // IMAGE URL
            )
            {
                $this->a = $a;
                $this->z = $z;
                $this->i = $i;
            }
        }
    }

    // MAKE AN ARRAY OF PROGRAM OBJECTS
    $programs = array
    ( new Program('0000', '0100', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host1.jpg')
    , new Program('0100', '0542', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host2.jpg')
    , new Program('0542', '0600', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host2.jpg')
    , new Program('0600', '0800', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host3.jpg')
    , new Program('0800', '1100', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host4.jpg')
    , new Program('1100', '1300', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host5.jpg')
    , new Program('1300', '1600', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host6.jpg')
    , new Program('1500', '1730', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host1.jpg')
    , new Program('1730', '1930', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host7.jpg')
    , new Program('1930', '2000', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host8.jpg')
    , new Program('2000', '2200', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host9.jpg')
    , new Program('2200', '2400', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host10.jpg')
    )
    ;

    // NORMALIZE THE DATETIME STRING
    $hhmm = date('hi', strtotime($hhmm));

    // DETERMINE THE IMAGE NEEDED
    foreach ($programs as $timeslot)
    {
        if ($hhmm >= $timeslot->a)
        {
            if ($hhmm <= $timeslot->z)
            {
                $url = $timeslot->i;
            }
        }
    }

    // CREATE THE IMAGE TAG
    $tag = <<<TAG
    <img alt="Host Image" title="$hhmm" src="$url" />
TAG;

    return $tag;
}


// TEST THE FUNCTION
echo '<br clear="all" />' . imageurl();
echo '<br clear="all" />' . imageurl('now+37 minutes');
echo '<br clear="all" />' . imageurl('now+237 minutes');

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
@esskayb2d: See http://php.net/manual/en/function.date-default-timezone-set.php required since PHP 5.1+  I think you could make the case that this is not really required if all your servers and clients were in UTC.  If any of your servers and clients are somewhere else, you might adjust time time zone to cause the DATETIME information to make more sense for the locale.
0
Ray PaseurCommented:
Sorry... Looks like I have a typo in line 40.  It should read something more like this
, new Program('1600', '1730', 'http://www.scotthennen.com/wp-content/themes/shs/schedule/host1.jpg')

Open in new window

Anyway, I hope the design pattern makes sense.  Best to all, ~Ray
0
billypilgrim32Author Commented:
Good Lord you guys are smart.
0
Ray PaseurCommented:
Thanks for the points -- it's a great question, ~Ray
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.