$rows = $users->fetchAll(PDO::FETCH_ASSOC);
$arrayByGroup = array();
$id = null;
foreach ($rows as $r) {
if($id != $r['id_group']) {
if (!is_null($id)) {
echo '</div>';
}
$id = $r['id_group'];
echo '<div class="id_group_' . $id . '">';
}
echo "<div>".$r["comments"]."<br>Written by ".$r["name"]."</div>";
}
echo '</div>'
Modification effectuée sur la base de la perspicacité de Matt Barrett.