正在制作一个 php 播放列表
其中一条记录包含多首歌曲,并用 #
我想看看是否有新歌
/music/David_Kersh/Another_You.mp4
存在于该行
/music/Abba/ABBA-When_I_Kissed_The_Teacher.mp4#/music/Aaron_Tippin/Aaron_Tippin\_-\__For_You_I_Will__Official_Video\_-\_Copy.mp4#
<?php
if (isset($_GET['song2']))
{
$song = $_GET['song2'];
$band = $_GET['band2'];
$playlist = $_GET['playlist']; //name of playlist
$songPath = "/music/".$band."/".$song."#";
$songPath2 = "/music/".$band."/".$song;//text version display
$connection = mysql_connect("localhost","***","****");
mysql_select_db("music")or die(mysql_error());
//Checks it Exists
$result = mysql_query("SELECT * FROM playlists WHERE path='$songPath'");
while ($row = mysql_fetch_assoc($result))
{
$path = $row['path'];
$find = explode("#",$path);
foreach($find as $key)
{
// if(strcmp($key, $songPath2) == 0)
if($key == $songPath2)
{
echo "<center>
<BR><BR><h1>It Exists in <br><br>".$playlist."</H1>";
}else
{
//if not exists Update that Playlist
$result = mysql_query("UPDATE playlists SET path=CONCAT(COALESCE(`path`,' '), '".$songPath."') WHERE name='".$playlist."'");
while ($row = mysql_fetch_assoc($result))
{}
}
}
}//whileEnd
}
?>
如果我刷新页面或再次重新输入,它会添加到播放列表,即使它已经存在
提前感谢
尝试下面的代码,这会起作用。也将 mysql 更改为 mysqli
<?php
if (isset($_GET['song2'])) {
$song = $_GET['song2'];
$band = $_GET['band2'];
$playlist = $_GET['playlist']; //name of playlist
$songPath = "/music/" . $band . "/" . $song . "#";
// use only this to match all without #
$songPath2 = "/music/" . $band . "/" . $song; //text version display
$connection = mysqli_connect("localhost", "***", "****");
mysqli_select_db("music") or die(mysql_error());
//Checks it Exists
$result = mysqli_query("SELECT * FROM playlists WHERE path like '%$songPath2%' ");
while ($row = mysqli_fetch_assoc($result)) {
$path = $row['path'];
$find = explode("#", $path);
if(in_array($songpath2,$find)) {
echo "<center><BR><BR><h1>It Exists in <br><br>" . $playlist . "</H1>";
} else {
//if not exists Update that Playlist
array_push($path,$songPath2);
$update_songs= implode('#',$path);
$rupdate = mysqli_query("UPDATE playlists SET path='$update_songs' WHERE name='" . $playlist . "'");
$result = mysqli_query("SELECT * FROM playlists WHERE path like '%$songPath%' ");
while ($row = mysql_fetch_assoc($result)) {}
}
} //whileEnd
}
?>