I’m hoping someone can help, I’m currently working on adding some features to a WordPress theme used on a local radio station. My query is with regards to displaying the current live show title, I have a written a php file that when processed by the title update form, updates a table in my db with the current show title (captured from the HTML form) but also captures the user id of whoever triggered the form, it then proceeds to update the Shoutcast server with the show title.
The idea behind this is to allow me to display dynamic wordpress content related to the current live DJ on the site – this works and has no issues, but what id like to do now is create a page that will check if the output of the Shoutcast server title matches the table in the db, if it does, then I’d like it to echo this output, if it is different I’d like it to use the output from the SC title instead.
I currently have 2 separate scripts that can output this info separately depending which is triggered but I need to combine these, (using an if / else command I’m assuming?) this is my current attempt but at the moment it doesn’t seem to output the db fields and will only output the SC title from the server;
<?php
require_once('../../wp-config.php'); // connection to WPdb
require_once('sc-config.php'); // connection to Shoutcast Server
$open = fsockopen($ip,$port);
fputs($open,"GET /7.html HTTP/1.1nUser-Agent:Mozillann");
$read = fread($open,1000);
$text = explode(",",$read);
$text = $text[6];
$query = "SELECT title, userID FROM sc_options where id= '0'"; // grab current show title and user id of the DJ that updated title from db
$result = mysql_query($query);
while($row = mysql_fetch_row($result))
{
$onAir_Title = $row[0];
$onAir_IMG = $row[1];
if ($onAir_Title == $text)
{
// start output
echo "$onAir_Title";
echo get_avatar( $onAir_IMG, 96);
}
else
{
echo "$text";
}
}
?>
Sorry if I’ve made a rookie mistake, I’m trying to learn as I go – any advice would be much appreciated!
Thank you
EDIT – these are the scripts in their original form, both working as they are;
This one checks the db and displays the output –
<?php
require_once('../../wp-config.php'); // open connection to WP
$query = "SELECT title, userID FROM sc_options where id= '0'";
$result = mysql_query($query);
while($row = mysql_fetch_row($result))
{
$onAir_Title = $row[0];
$onAir_IMG = $row[1];
// output
echo "$onAir_Title";
echo get_avatar( $onAir_IMG, 96);
}
?>
And this one displays the shoutcast title from the shoutcast server
<div style="Visibility: Hidden; Position: Absolute;">
<?php
$open = fsockopen("198.154.106.116","6002");
if ($open) {
fputs($open,"GET /7.html HTTP/1.1nUser-Agent:Mozillann");
$read = fread($open,1000);
$text = explode(",",$read);
$text = $text[6];
} else { $text="connection refused."; }
?>
</div>
<?php
echo "$text";
?>
If anyone is interested, I managed to make this work, I have re-written how the title is checked on the SC Server and finally got it working..