Jump to content

How can I combine these 2 and decide on the output?


Gordon_

Recommended Posts

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, regardless of the db title, it's almost as if it doesn't even acknowledge it and each time just outputs the shoutcast server info;

<?php
require_once('../../wp-config.php'); // open connection to WPdb
require_once('sc-config.php'); // open connection to Shoutcast Server

$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];
}
$open = fsockopen("$ip","$port"); 
if ($open) { 
fputs($open,"GET /7.html HTTP/1.1\nUser-Agent:Mozilla\n\n"); 
$read = fread($open,1000); 
$text = explode(",",$read); 
$text = $text[6]; 
} else { $text="connection refused."; }

$scast = $text;
$scdb = $onAir_Title;

if ($scdb == $scast)
 {
echo $onAir_Title;
echo get_avatar( $onAir_IMG, 96);
 }
else
 {
echo $text;
 }
?>

These are the original files, they work exactly as they should apart, but for the life of me I cannot get them to work as one

 

Shoutcast 

<div style="Visibility: Hidden; Position: Absolute;"> 
<?php 
$open = fsockopen("198.154.106.116","6002"); 
if ($open) { 
fputs($open,"GET /7.html HTTP/1.1\nUser-Agent:Mozilla\n\n"); 
$read = fread($open,1000); 
$text = explode(",",$read); 
$text = $text[6]; 
} else { $text="connection refused."; } 
?> 
</div> 
<?php
echo $text;
?>

Wordpress db 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);
} 

?>

Just to sum it up, would I'd like to happen, is have the file load, check the title in the database row, if that matches the title being displayed by shoutcast, echo the data from the table, if the output from shoutcast is different, then echo the output from shoutcast instead.

Edited by Gordon_
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.