簡體   English   中英

在html中對mySQL結果進行排序和分組

[英]Sorting and Grouping mySQL Results in html

我有一個帶有3個字段的mysql表:id,client,group和一些數據。

我需要在css表上按組顯示結果,如下所示:

group A
    - John
    - Paul
    - Ringo
    - George

group B
    - Mick
    - Keith
    - Charlie

group C
    - Axl
    - Slash
    - Izzy

我要在里面放一會兒嗎? 在這種條件下,我真的沒有邏輯……有人可以幫我嗎?

到目前為止,我有:

while($row = mysql_fetch_array($result) ){
    echo "<div>".$row['group']."</div>";

    while($currentGroup != $group ){                        
        echo "<div><B>".$row['id']."</b></div>";
        echo "<div>".$row['client']."</div>";
    }
    $currentGroup = $group;
}

謝謝!

像這樣:

$currentGroup = false;

while ($row = mysql_fetch_array($result))
{

    if ($row['group'] !== $currentGroup)
    {
        echo "<div>".$row['group']."</div>";
        $currentGroup = $row['group'];
    }

    echo "<div><B>".$row['id']."</b></div>";
    echo "<div>".$row['client']."</div>";
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM