我有 2 个 MySQL 表,一个用于存储专辑,另一个用于存储歌曲。我在表格中显示专辑列表,我希望能够添加一个名为songs
显示此专辑中歌曲数量的列。我现在拥有它的方式只是把我的桌子弄乱了:
感谢大家的帮助!
假设“播放列表”是您认为的专辑,并且第一个while
循环在播放列表上进行迭代,我将像这样重写您的代码:
while($row = mysql_fetch_array($rs)) {
echo "<tr>\n";
echo "<td>".$row['playlist_id']."</td>";
// Assuming playlist_id is an integer value in your database
$query = "
SELECT Playlist_id, COUNT(Playlist_id) AS songCount
FROM ws_music
WHERE Playlist_id = ". intval ($row['playlist_id']) ."
GROUP BY Playlist_id
";
$result = mysql_query($query) or die(mysql_error());
// No need for the second while loop
$row2 = mysql_fetch_array($result);
echo "<td>There are ". $row2['songCount'] ." ". $row2['Playlist_id'] ." song.</td>";
echo "</tr>";
}