gpt4 book ai didi

php - MySQL/PHP 计数

转载 作者:行者123 更新时间:2023-11-29 14:11:31 25 4
gpt4 key购买 nike

我有 2 个 MySQL 表,一个用于存储专辑,另一个用于存储歌曲。我在表格中显示专辑列表,并且希望能够添加一个名为 songs 的列来显示该专辑中的歌曲数量。我现在的方式只会弄乱我的 table :

感谢大家的帮助!

最佳答案

假设“播放列表”是您认为的专辑,并且第一个 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>";
}

关于php - MySQL/PHP 计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13441092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com