Jump to content

Tricky Php Timecode Issue for Radio Site - Willing to Pay for Solution


willvbcfc

Recommended Posts

Hey all. This could be a long, but rewarding riddle to crack for you coders out there. I'm willing to offer whoever cracks it £20 ($31 or €23) which I'll transfer via paypal upon completion.

 

I'm currently making a site for my University's radio station and I'm doing it by using some advanced wordpress techniques and modding the hell out of plugins. Just to let you know now, I'm not a computer science student, but I have good self learned knowledge of html/css, but my php is a little sketchy.

 

Therefore, I've got a bit stuck on one particular feature. I am required to make an 'On Air Now' tab which displays the name and image of the show that is currently on air.

 

At the moment, I have the following code working well:

 

<?php
date_default_timezone_set('Europe/London');
$h = date('G'); //set variable $h to the hour of the day
$d = date('w'); //set variable $d to the day of the week.
$year = date('Y'); //set variable $year to the current year


//G is the date key for hours in 24 format (not 12), with no leading 0s, like 02.
//Enter show details for each hour within the parses.

// MON SCHEDULE
if ($d == 1 && $h >= 0 && $h < 1) { $showname = ' '; }
else if ($d == 1 && $h >= 1 && $h < 2) { $showname = ' '; }
else if ($d == 1 && $h >= 2 && $h < 3) { $showname = ' '; }
else if ($d == 1 && $h >= 3 && $h < 4) { $showname = ' '; }
else if ($d == 1 && $h >= 4 && $h < 5) { $showname = ' '; }
else if ($d == 1 && $h >= 5 && $h < 6) { $showname = ' '; }
else if ($d == 1 && $h >= 6 && $h < 7) { $showname = ' '; }
else if ($d == 1 && $h >= 7 && $h <  { $showname = ' '; }
else if ($d == 1 && $h >= 8 && $h < 9) { $showname = ' '; }
else if ($d == 1 && $h >= 9 && $h < 10) { $showname = ' '; }
else if ($d == 1 && $h >= 10 && $h < 11) { $showname = ' '; }
else if ($d == 1 && $h >= 11 && $h < 12) { $showname = ' '; }
else if ($d == 1 && $h >= 12 && $h < 13) { $showname = ' '; }
else if ($d == 1 && $h >= 13 && $h < 14) { $showname = ' '; }
else if ($d == 1 && $h >= 14 && $h < 15) { $showname = ' '; }
else if ($d == 1 && $h >= 15 && $h < 16) { $showname = ' '; }
else if ($d == 1 && $h >= 16 && $h < 17) { $showname = ' '; }
else if ($d == 1 && $h >= 17 && $h < 18) { $showname = ' '; }
else if ($d == 1 && $h >= 18 && $h < 19) { $showname = ' '; }
else if ($d == 1 && $h >= 19 && $h < 20) { $showname = ' '; }
else if ($d == 1 && $h >= 20 && $h < 21) { $showname = ' '; }
else if ($d == 1 && $h >= 21 && $h < 22) { $showname = ' '; }
else if ($d == 1 && $h >= 22 && $h < 23) { $showname = ' '; }
else if ($d == 1 && $h >= 23 && $h < 0) { $showname = ' '; }

// TUES SCHEDULE
if ($d == 2 && $h >= 0 && $h < 1) { $showname = ' '; }
else if ($d  == 2 && $h >= 1 && $h < 2) { $showname = ' '; }
else if ($d  == 2 && $h >= 2 && $h < 3) { $showname = ' '; }
else if ($d  == 2 && $h >= 3 && $h < 4) { $showname = ' '; }
else if ($d  == 2 && $h >= 4 && $h < 5) { $showname = ' '; }
else if ($d  == 2 && $h >= 5 && $h < 6) { $showname = ' '; }
else if ($d  == 2 && $h >= 6 && $h < 7) { $showname = ' '; }
else if ($d  == 2 && $h >= 7 && $h <  { $showname = ' '; }
else if ($d  == 2 && $h >= 8 && $h < 9) { $showname = ' '; }
else if ($d  == 2 && $h >= 9 && $h < 10) { $showname = ' '; }
else if ($d  == 2 && $h >= 10 && $h < 11) { $showname = ' '; }
else if ($d  == 2 && $h >= 11 && $h < 12) { $showname = ' '; }
else if ($d  == 2 && $h >= 12 && $h < 13) { $showname = ' '; }
else if ($d  == 2 && $h >= 13 && $h < 14) { $showname = ' '; }
else if ($d  == 2 && $h >= 14 && $h < 15) { $showname = ' '; }
else if ($d  == 2 && $h >= 15 && $h < 16) { $showname = ' '; }
else if ($d  == 2 && $h >= 16 && $h < 17) { $showname = ' '; }
else if ($d  == 2 && $h >= 17 && $h < 18) { $showname = ' '; }
else if ($d  == 2 && $h >= 18 && $h < 19) { $showname = ' '; }
else if ($d  == 2 && $h >= 19 && $h < 20) { $showname = ' '; }
else if ($d  == 2 && $h >= 20 && $h < 21) { $showname = ' '; }
else if ($d  == 2 && $h >= 21 && $h < 22) { $showname = ' '; }
else if ($d  == 2 && $h >= 22 && $h < 23) { $showname = ' '; }
else if ($d  == 2 && $h >= 23 && $h < 0) { $showname = ' '; }

// WEDS SCHEDULE
if ($d  == 3 && $h >= 0 && $h < 1) { $showname = ' '; }
else if ($d   == 3 && $h >= 1 && $h < 2) { $showname = ' '; }
else if ($d   == 3 && $h >= 2 && $h < 3) { $showname = ' '; }
else if ($d   == 3 && $h >= 3 && $h < 4) { $showname = ' '; }
else if ($d   == 3 && $h >= 4 && $h < 5) { $showname = ' '; }
else if ($d   == 3 && $h >= 5 && $h < 6) { $showname = ' '; }
else if ($d   == 3 && $h >= 6 && $h < 7) { $showname = ' '; }
else if ($d   == 3 && $h >= 7 && $h <  { $showname = ' '; }
else if ($d   == 3 && $h >= 8 && $h < 9) { $showname = ' '; }
else if ($d   == 3 && $h >= 9 && $h < 10) { $showname = ' '; }
else if ($d   == 3 && $h >= 10 && $h < 11) { $showname = ' '; }
else if ($d   == 3 && $h >= 11 && $h < 12) { $showname = ' '; }
else if ($d   == 3 && $h >= 12 && $h < 13) { $showname = ' '; }
else if ($d   == 3 && $h >= 13 && $h < 14) { $showname = ' '; }
else if ($d   == 3 && $h >= 14 && $h < 15) { $showname = ' '; }
else if ($d   == 3 && $h >= 15 && $h < 16) { $showname = ' '; }
else if ($d   == 3 && $h >= 16 && $h < 17) { $showname = ' '; }
else if ($d   == 3 && $h >= 17 && $h < 18) { $showname = ' '; }
else if ($d   == 3 && $h >= 18 && $h < 19) { $showname = ' '; }
else if ($d   == 3 && $h >= 19 && $h < 20) { $showname = ' '; }
else if ($d   == 3 && $h >= 20 && $h < 21) { $showname = ' '; }
else if ($d   == 3 && $h >= 21 && $h < 22) { $showname = ' '; }
else if ($d   == 3 && $h >= 22 && $h < 23) { $showname = ' '; }
else if ($d   == 3 && $h >= 23 && $h < 0) { $showname = ' '; }

// THURS SCHEDULE
if ($d  == 4 && $h >= 0 && $h < 1) { $showname = ' '; }
else if ($d   == 4 && $h >= 1 && $h < 2) { $showname = ' '; }
else if ($d   == 4 && $h >= 2 && $h < 3) { $showname = ' '; }
else if ($d   == 4 && $h >= 3 && $h < 4) { $showname = ' '; }
else if ($d   == 4 && $h >= 4 && $h < 5) { $showname = ' '; }
else if ($d   == 4 && $h >= 5 && $h < 6) { $showname = ' '; }
else if ($d   == 4 && $h >= 6 && $h < 7) { $showname = ' '; }
else if ($d   == 4 && $h >= 7 && $h <  { $showname = ' '; }
else if ($d   == 4 && $h >= 8 && $h < 9) { $showname = ' '; }
else if ($d   == 4 && $h >= 9 && $h < 10) { $showname = ' '; }
else if ($d   == 4 && $h >= 10 && $h < 11) { $showname = ' '; }
else if ($d   == 4 && $h >= 11 && $h < 12) { $showname = ' '; }
else if ($d   == 4 && $h >= 12 && $h < 13) { $showname = ' '; }
else if ($d   == 4 && $h >= 13 && $h < 14) { $showname = 'Test'; }
else if ($d   == 4 && $h >= 14 && $h < 15) { $showname = ' '; }
else if ($d   == 4 && $h >= 15 && $h < 16) { $showname = ' '; }
else if ($d   == 4 && $h >= 16 && $h < 17) { $showname = ' '; }
else if ($d   == 4 && $h >= 17 && $h < 18) { $showname = ' '; }
else if ($d   == 4 && $h >= 18 && $h < 19) { $showname = ' '; }
else if ($d   == 4 && $h >= 19 && $h < 20) { $showname = ' '; }
else if ($d   == 4 && $h >= 20 && $h < 21) { $showname = ' '; }
else if ($d   == 4 && $h >= 21 && $h < 22) { $showname = ' '; }
else if ($d   == 4 && $h >= 22 && $h < 23) { $showname = ' '; }
else if ($d   == 4 && $h >= 23 && $h < 0) { $showname = ' '; }

// FRI SCHEDULE
if ($d == 5 && $h >= 0 && $h < 1) { $showname = ' '; }
else if ($d   == 5 && $h >= 1 && $h < 2) { $showname = ' '; }
else if ($d   == 5 && $h >= 2 && $h < 3) { $showname = ' '; }
else if ($d   == 5 && $h >= 3 && $h < 4) { $showname = ' '; }
else if ($d   == 5 && $h >= 4 && $h < 5) { $showname = ' '; }
else if ($d   == 5 && $h >= 5 && $h < 6) { $showname = ' '; }
else if ($d   == 5 && $h >= 6 && $h < 7) { $showname = ' '; }
else if ($d   == 5 && $h >= 7 && $h <  { $showname = ' '; }
else if ($d   == 5 && $h >= 8 && $h < 9)  { $showname = ' '; }
else if ($d   == 5 && $h >= 9 && $h < 10) { $showname = ' '; }
else if ($d   == 5 && $h >= 10 && $h < 11) { $showname = ' '; }
else if ($d   == 5 && $h >= 11 && $h < 12) { $showname = ' '; }
else if ($d   == 5 && $h >= 12 && $h < 13) { $showname = ' '; }
else if ($d   == 5 && $h >= 13 && $h < 14) { $showname = ' '; }
else if ($d   == 5 && $h >= 14 && $h < 15) { $showname = ' '; }
else if ($d   == 5 && $h >= 15 && $h < 16) { $showname = ' '; }
else if ($d   == 5 && $h >= 16 && $h < 17) { $showname = ' '; }
else if ($d   == 5 && $h >= 17 && $h < 18) { $showname = ' '; }
else if ($d   == 5 && $h >= 18 && $h < 19) { $showname = ' '; }
else if ($d   == 5 && $h >= 19 && $h < 20) { $showname = ' '; }
else if ($d   == 5 && $h >= 20 && $h < 21) { $showname = ' '; }
else if ($d   == 5 && $h >= 21 && $h < 22) { $showname = ' '; }
else if ($d   == 5 && $h >= 22 && $h < 23) { $showname = ' '; }
else if ($d   == 5 && $h >= 23 && $h < 0) { $showname = ' '; }


// SAT SCHEDULE
if ($d  == 6 && $h >= 0 && $h < 1) { $showname = ' '; }
else if ($d   == 6 && $h >= 1 && $h < 2) { $showname = ' '; }
else if ($d   == 6 && $h >= 2 && $h < 3) { $showname = ' '; }
else if ($d   == 6 && $h >= 3 && $h < 4) { $showname = ' '; }
else if ($d   == 6 && $h >= 4 && $h < 5) { $showname = ' '; }
else if ($d   == 6 && $h >= 5 && $h < 6) { $showname = ' '; }
else if ($d   == 6 && $h >= 6 && $h < 7) { $showname = ' '; }
else if ($d   == 6 && $h >= 7 && $h <  { $showname = ' '; }
else if ($d   == 6 && $h >= 8 && $h < 9) { $showname = ' '; }
else if ($d   == 6 && $h >= 9 && $h < 10) { $showname = ' '; }
else if ($d   == 6 && $h >= 10 && $h < 11) { $showname = ' '; }
else if ($d   == 6 && $h >= 11 && $h < 12) { $showname = ' '; }
else if ($d   == 6 && $h >= 12 && $h < 13) { $showname = ' '; }
else if ($d   == 6 && $h >= 13 && $h < 14) { $showname = ' '; }
else if ($d   == 6 && $h >= 14 && $h < 15) { $showname = ' '; }
else if ($d   == 6 && $h >= 15 && $h < 16) { $showname = ' '; }
else if ($d   == 6 && $h >= 16 && $h < 17) { $showname = ' '; }
else if ($d   == 6 && $h >= 17 && $h < 18) { $showname = ' '; }
else if ($d   == 6 && $h >= 18 && $h < 19) { $showname = ' '; }
else if ($d   == 6 && $h >= 19 && $h < 20) { $showname = ' '; }
else if ($d   == 6 && $h >= 20 && $h < 21) { $showname = ' '; }
else if ($d   == 6 && $h >= 21 && $h < 22) { $showname = ' '; }
else if ($d   == 6 && $h >= 22 && $h < 23) { $showname = ' '; }
else if ($d   == 6 && $h >= 23 && $h < 0) { $showname = ' '; }

// SUN SCHEDULE
if ($d  == 0 && $h >= 0 && $h < 1) { $showname = ' '; }
else if ($d   == 0 && $h >= 1 && $h < 2) { $showname = ' '; }
else if ($d   == 0 && $h >= 2 && $h < 3) { $showname = ' '; }
else if ($d   == 0 && $h >= 3 && $h < 4) { $showname = ' '; }
else if ($d   == 0 && $h >= 4 && $h < 5) { $showname = ' '; }
else if ($d   == 0 && $h >= 5 && $h < 6) { $showname = ' '; }
else if ($d   == 0 && $h >= 6 && $h < 7) { $showname = ' '; }
else if ($d   == 0 && $h >= 7 && $h <  { $showname = ' '; }
else if ($d   == 0 && $h >= 8 && $h < 9) { $showname = ' '; }
else if ($d   == 0 && $h >= 9 && $h < 10) { $showname = ' '; }
else if ($d   == 0 && $h >= 10 && $h < 11) { $showname = ' '; }
else if ($d   == 0 && $h >= 11 && $h < 12) { $showname = ' '; }
else if ($d   == 0 && $h >= 12 && $h < 13) { $showname = ' '; }
else if ($d   == 0 && $h >= 13 && $h < 14) { $showname = ' '; }
else if ($d   == 0 && $h >= 14 && $h < 15) { $showname = ' '; }
else if ($d   == 0 && $h >= 15 && $h < 16) { $showname = ' '; }
else if ($d   == 0 && $h >= 16 && $h < 17) { $showname = ' '; }
else if ($d   == 0 && $h >= 17 && $h < 18) { $showname = ' '; }
else if ($d   == 0 && $h >= 18 && $h < 19) { $showname = ' '; }
else if ($d   == 0 && $h >= 19 && $h < 20) { $showname = ' '; }
else if ($d   == 0 && $h >= 20 && $h < 21) { $showname = ' '; }
else if ($d   == 0 && $h >= 21 && $h < 22) { $showname = ' '; }
else if ($d   == 0 && $h >= 22 && $h < 23) { $showname = ' '; }
else if ($d   == 0 && $h >= 23 && $h < 0) { $showname = ' '; }


echo ''.$showname.'';

?>

 

Simple, yes? However, as I am to be leaving Uni at the end of this academic year, I can't count on the fact that the future site maintainers will be able to edit the php, which either way would be a long and boring process. Therefore, I need to automate the script to recognise which show is on air.

 

All of my show pages are defined by wordpress categories and I'm using a category meta plugin to display extra data.

 

Therefore, I presume I need to firstly query my show categories (all are a child of category ID 3) by the day and timecode meta that I have defined using the meta plugin:

 

get_terms_meta($category->term_id, 'dayvalue');

get_terms_meta($category->term_id, 'timecodestart');

get_terms_meta($category->term_id, 'timecodeend');

 

Then I need to use a function to say IF $dayvalue=1 (for Monday, 2 for Tuesday, 3 for Wednesday etc & 0 for Sunday) and if timecode start is, for example, >12 && <13 ...then it displays its category name and $categoryimage for that particular show.

 

I'll need to put that same code within the parses for every hour of every day.

 

That's the logic - I just don't know how to code it and there really isn't much about this area on the net!

 

As I said, I'm willing to offer the successful person a bit of money because this is quite a crucial part of my project that needs to be completed!

 

Either respond here or contact me on willvbcfc@gmail.com.

Link to comment
Share on other sites

The problem here is that you are using the wrong method. Setting variables based on time is cumbersome when you need to take into account every hour of every day.

 

Instead of extracting all shows, then checking every row - you should use a SQL query which will fetch only the show you need based on the time range in the database (should be one of the columns for the show) and the current time.

 

If you try to do that, I'm sure you'll get this done in no time.

Link to comment
Share on other sites

The problem here is that you are using the wrong method. Setting variables based on time is cumbersome when you need to take into account every hour of every day.

 

Instead of extracting all shows, then checking every row - you should use a SQL query which will fetch only the show you need based on the time range in the database (should be one of the columns for the show) and the current time.

 

If you try to do that, I'm sure you'll get this done in no time.

 

I agree, that does sound easier... but I still need to use the meta data to call the SQL query and I'm not sure what code I'd use to get it specifically without the code for the individual hours as posted above!

Link to comment
Share on other sites

Sadly sql isn't my strong point but this is fairly simple. No matter what data you have to get, the end method should be a single sql query which fetches the show based on current time.

 

Here is a tutorial I just found on what you should be doing:

 

http://www.databasejournal.com/features/mssql/article.php/2209321/Working-with-SQL-Server-DateTime-Variables-Part-Three---Searching-for-Particular-Date-Values-and-Ranges.htm

 

Because you want to filter by hour, you would get the higher and lower end of the current hour in a timestamp (or whatever your column uses for the show) and use those two for the between values.

 

Do you have details on the table which deals with the shows? Does it contain timestamp information in a column?

Link to comment
Share on other sites

Sadly sql isn't my strong point but this is fairly simple. No matter what data you have to get, the end method should be a single sql query which fetches the show based on current time.

 

Here is a tutorial I just found on what you should be doing:

 

http://www.databasejournal.com/features/mssql/article.php/2209321/Working-with-SQL-Server-DateTime-Variables-Part-Three---Searching-for-Particular-Date-Values-and-Ranges.htm

 

Because you want to filter by hour, you would get the higher and lower end of the current hour in a timestamp (or whatever your column uses for the show) and use those two for the between values.

 

Do you have details on the table which deals with the shows? Does it contain timestamp information in a column?

 

I apologise for any naivety in this issue, but each show is posted as a wordpress category in that particular taxonomy. I'm really not sure when it comes to SQL tables. In all honesty, that's a little more advanced than where I've been before.

 

The very basics of what I need is, when creating the category in the wordpress dashboard, users are able to input the show's day and time and use that as the call up reference for the On Air Now function.

 

Is what you've just said still applicable now I've made it a little bit clearer?

Link to comment
Share on other sites

Sadly sql isn't my strong point but this is fairly simple. No matter what data you have to get, the end method should be a single sql query which fetches the show based on current time.

 

Here is a tutorial I just found on what you should be doing:

 

http://www.databasejournal.com/features/mssql/article.php/2209321/Working-with-SQL-Server-DateTime-Variables-Part-Three---Searching-for-Particular-Date-Values-and-Ranges.htm

 

Because you want to filter by hour, you would get the higher and lower end of the current hour in a timestamp (or whatever your column uses for the show) and use those two for the between values.

 

Do you have details on the table which deals with the shows? Does it contain timestamp information in a column?

 

I apologise for any naivety in this issue, but each show is posted as a wordpress category in that particular taxonomy. I'm really not sure when it comes to SQL tables. In all honesty, that's a little more advanced than where I've been before.

 

The very basics of what I need is, when creating the category in the wordpress dashboard, users are able to input the show's day and time and use that as the call up reference for the On Air Now function.

 

Is what you've just said still applicable now I've made it a little bit clearer?

 

I would think it is still applicable. The schedule information will be stored somewhere. However, even though you capture show day and time, you should also capture show 'timestamp' which is a number (3424243241) format of that particular day and time in seconds. Sadly though, because this is moving into the realms of wordpress it becomes even harder for me to direct you.

 

For that reason, might be better if you check the wordpress forums.

 

However, I think I can conjur something up to deal with this using a loop. I can't promise it will do everything but it will be more than what you have now :)

 

Give me 20-30 mins.

Link to comment
Share on other sites

Right, to do php way without using sql entirely you will need to get an array of these shows with the day, timecodestart and timecodeend.

 

Do you know how to do loops? Like loop over this array and output. I'd need to see an example output of the above. With that, I should be able to easily extract the show based on current day and hour.

Link to comment
Share on other sites

Right, to do php way without using sql entirely you will need to get an array of these shows with the day, timecodestart and timecodeend.

 

Do you know how to do loops? Like loop over this array and output. I'd need to see an example output of the above. With that, I should be able to easily extract the show based on current day and hour.

 

I know how to do loops, sure. I'm currently representing $day as:

 

0 Sunday

1 Monday

2 Tuesday

3 Wednesday

4 Thursday

5 Friday

6 Saturday

 

$timecodestart and $timecodeend are simply the 24 hour clock times. For example, 3pm is 15.

 

It seems a bit flimsy to me, but the best I could come up with. Do you need any more information?

Link to comment
Share on other sites

Sorry, yeh, I mean I need an example of your array with all the categories/shows.

 

Ok - I think this is how it's done in wordpress...

 

<?php
//display all categories that have at least one post, separate each category with comma+space, put each category in quotes
$categories=get_categories();
if ($categories) {
$cat_count =count($categories);
$output = '';
foreach($categories as $category) {
    if ($category->count > 1) {
    $output .= '"<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>", ';
}
}
}
echo '<p>' . substr($output, 0, -2) . '</p>';  // display all but the last comma
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.