我希望有人能帮助我,我目前正在为本地广播电台使用的Wordpress主题添加一些功能。我的查询是关于显示当前直播节目标题,我写了一个php文件,当由标题更新表单处理时,更新我的数据库中的表与当前的节目标题(从HTML表单捕获),但也捕获谁触发表单的用户id,然后它继续更新showcast服务器与节目标题。
背后的想法是让我显示动态wordpress的内容在网站上有关当前现场DJ -这是没有问题,但现在我想做的是创建一个页面,该页面将检查如果Shoutcast服务器的输出标题匹配数据库中的表,如果是这样,那么我想它呼应这个输出,如果是不同的我想它使用SC的输出标题。
我目前有2个单独的脚本,可以分别输出此信息取决于哪一个触发,但我需要结合这些,(使用if/else命令我假设?)这是我目前的尝试,但目前它似乎没有输出db字段,只会输出SC标题从服务器;
<?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.1'nUser-Agent:Mozilla'n'n");
$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";
}
}
?>
如果我犯了一个新手错误,我很抱歉,我正在努力学习,任何建议都会非常感激! 谢谢
EDIT -这些都是原始形式的脚本,都按原样工作;
检查db并显示输出-
<?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);
}
?>
这个显示来自广播服务器的广播标题
<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";
?>
如果有人感兴趣,我设法使这项工作,我已经重写了如何在SC服务器上检查标题,并最终使其工作..
<?php
/* ----------- Server configuration ---------- */
require_once('sc-config.php'); // Shoutcast
require_once('../../wp-config.php'); // WPdb
/* ----- No need to edit below this line ----- */
/* ------------------------------------------- */
$fp = @fsockopen($ip,$port,$errno,$errstr,1); // Open connection to Shoutcast
if (!$fp)
{
echo "Connection refused"; // Displays when sever is offline
}
else
{
fputs($fp, "GET /7.html HTTP/1.0'r'nUser-Agent: Mozilla'r'n'r'n"); // Get Stream Title
while (!feof($fp))
{
$info = fgets($fp);
}
$info = str_replace('</body></html>', "", $info);
$split = explode(',', $info);
$query = "SELECT title, userID FROM sc_options where id = '1'"; // Grab last title update from db table row
$result = mysql_query($query);
while($row = mysql_fetch_row($result))
$onAir_Title = $row[0]; // Create db show title string
$onAir_IMG = $row[1]; // User ID of last show update
if ($onAir_Title == $split[6]) // Check table row matches live stream title
{
echo $onAir_Title;
echo get_avatar( $onAir_IMG, 96); // User ID
}
else // If it doesn't match output the title from the SC server
{
$title = str_replace('''', '`', $split[6]);
$title = str_replace(',', ' ', $title);
echo "$title"; // Displays song
}
}
?>