这很简单,很抱歉打扰了,但我已经思考了好几个小时,但我想不出一个解决方案:(
我的数据库查询抛出:
ID – NAME – LASTNAME – SONG — ALBUM
12 –Bryan – Ferry – Rescue Me – Taxi
12 –Bryan – Ferry – Just One Look –Taxi
99 – Nick – Cave – Wonderful Life – Nocturama
我需要它在我的网页中显示的方式是:
布莱恩·费里
救我(出租车)
看一眼(出租车)
尼克凯夫
美好生活(夜景)
好吧,我在我的 php 脚本中,在查询结果循环中,但我不知道如何继续......
while ($row=mysqli_fetch_assoc($result))
{
//what do I have to do here to get the format I need ??
}
非常感谢!!
最佳答案
如果你想用 PHP 做这件事,我会这样做......
$oldid = -999;
while($row = mysql_fetch_assoc($result)) {
if ($row["id"] != $oldid) {
echo($row["name"]." ".$row["lastname"]."<br />");
$oldid = $row["id"];
}
echo($row["song"]." (".$row["album"].")<br />");
}
每次循环时,只需将艺术家 ID 与上次的 ID 进行比较即可。如果不同打印艺术家姓名并更新 $oldid,否则只打印歌曲名称
关于PHP:表示查询结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17211308/