题
我提出申请,采取从互联网广播流正在播放的标题和艺术家,而且我已经在纯文本此页面上显示:
http://thelisthq.net/z1035.php
的输出是简单的PHP“回声$变量”命令,但$变量是不断变化的,因此,如何做I $变量的每个不同值存储到数据库中。最终的计划,以保持所有在一定的时间段播放的歌曲的列表。
解决方案
你必须建立PHP脚本每隔x分钟左右,的,而不是呼应的结果运行,则请根据当前播放的歌曲最近的数据库条目,如果是不同的,添加新记录
首先,一些SQL来设置一个新的表:
CREATE TABLE SongList (
ID int primary key auto_increment not null,
Song char(255) not null,
PlayTime Datetime not null
);
然后,修改你的PHP脚本插入到数据库中,而不是呼应屏幕记录:
<?php
$song = get_song(); //not sure how you're doing that
$sql = "SELECT Song FROM SongList ORDER BY PlayTime DESC LIMIT 1";
list($prevSong) = mysql_fetch_row(mysql_query($sql));
if ($song !== $prevSong) {
$sql = "INSERT INTO SongList (Song, PlayTime) VALUES ('$song', NOW())";
mysql_query($sql);
}
?>
设置计划任务或cron作业php -f z1035.php
每分钟运行一次。
要看到的歌曲的整个列表,创建一个新的php文件station_history.php
<html>
<body>
<pre>
<?php
$sql = "SELECT Song, PlayTime FROM SongList LIMIT 20"; // Just the last 20 songs
$result = mysql_query($sql);
while(list($song, $playtime) = mysql_fetch_row($result)) {
echo "[$playtime] $song\n";
}
?>
</pre>
</body>
</html>
不隶属于 StackOverflow