Solved

Radio station php script

Posted on 2012-03-12
21
496 Views
Last Modified: 2012-03-15
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!
0
Comment
Question by:billypilgrim32
  • 8
  • 7
  • 6
21 Comments
 
LVL 15

Expert Comment

by:Ess Kay
ID: 37710360
0
 

Author Comment

by:billypilgrim32
ID: 37710873
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
 
LVL 15

Expert Comment

by:Ess Kay
ID: 37710932
see if it will work without the wordpress first
0
 

Author Comment

by:billypilgrim32
ID: 37711021
no dice. im just seeing an empty image tag:

<img src="">
0
 
LVL 15

Expert Comment

by:Ess Kay
ID: 37711194
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
 

Author Comment

by:billypilgrim32
ID: 37711244
after inserting <?php   echo $d ?> it's now displaying a 1.
0
 
LVL 15

Expert Comment

by:Ess Kay
ID: 37711359
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
 

Author Comment

by:billypilgrim32
ID: 37711418
now i'm getting:

 $000 0
0
 
LVL 15

Expert Comment

by:Ess Kay
ID: 37711557
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
 

Author Comment

by:billypilgrim32
ID: 37711623
no problem! now i'm getting:

 month 33
hhmm 33
h 5
d 1
yr 2012
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 15

Expert Comment

by:Ess Kay
ID: 37711716
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37712317
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
 

Author Comment

by:billypilgrim32
ID: 37716150
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37716216
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
 
LVL 15

Assisted Solution

by:Ess Kay
Ess Kay earned 200 total points
ID: 37716442
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
 
LVL 15

Expert Comment

by:Ess Kay
ID: 37716527
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
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 300 total points
ID: 37716759
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37716795
@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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37716846
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
 

Author Comment

by:billypilgrim32
ID: 37725931
Good Lord you guys are smart.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37726532
Thanks for the points -- it's a great question, ~Ray
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now