PHP:表示查询结果


PHP: representing query results

这很简单,我很抱歉打扰它,但我已经花了几个小时思考如何做到这一点,我不能拿出一个解决方案:(

我的数据库查询抛出:

ID – NAME – LASTNAME –  SONG —    ALBUM
12 –Bryan – Ferry –  Rescue Me –   Taxi 
12 –Bryan – Ferry –  Just One Look –Taxi 
99 – Nick – Cave –   Wonderful Life – Nocturama

我需要它显示在我的网页的方式是:

布莱恩渡轮

拯救我(出租车)

Just One Look (Taxi)

尼克洞穴

美妙人生(夜曲)

好吧,我在我的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与上次是什么。如果不同,则打印艺人姓名并更新$oldid,否则仅打印歌曲标题