tags:

views:

28

answers:

1

I have a mysql table with 3 fields: id, client, group and some data.

I need to display the results in groups, on a css table, like this:

group A
    - John
    - Paul
    - Ringo
    - George

group B
    - Mick
    - Keith
    - Charlie

group C
    - Axl
    - Slash
    - Izzy

I have to put a while inside another while? I really don't get the logic behing this conditional... Can someone help me?

I have this so far:

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;
}

Thanks!

A: 

Like this:

$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>";
}
Greg
Really thanks Greg! This was REALLY fast!
ookla