www.webdeveloper.com
Results 1 to 7 of 7

Thread: Radio Station On Air Script

  1. #1
    Join Date
    Dec 2004
    Location
    UK
    Posts
    18

    Radio Station On Air Script

    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

  2. #2
    Join Date
    Oct 2004
    Location
    Portland, OR
    Posts
    145
    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.
    PHP Code:
    <?
    // 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

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    18
    Looks great, will have a go tomorrow, thanks!

  4. #4
    Join Date
    Dec 2004
    Location
    UK
    Posts
    18
    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:

    Code:
    <?
    // 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

  5. #5
    Join Date
    May 2013
    Posts
    2
    hi there i'm having the same problem with the code.
    i have the second bit of code, this one


    <?
    // set up an array with hours of the day as KEY and dj names as VALUE
    $times=
    array(
    /* 12:00pm */ '12' => AUTODJ',
    /* 1:00am */ '13' => 'AUTODJ',
    /* 3:00am */ '14' => 'AUTODJ',
    /* 12:00pm */ '15' => 'AUTODJ'
    /* 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 nowplaying.php and nothing is happening? please help

  6. #6
    Join Date
    Feb 2013
    Location
    USA
    Posts
    40
    Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic.

  7. #7
    Join Date
    May 2013
    Posts
    2
    can someone please help me with this script
    many thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles