As long as you order it by the user_id, you could keep a note of the previous used_id, and only throw a new row break in the html when the user_id changes.
prevuser = "";
for each (row) {
if (row[user_id] <> prevuser {
if (prevuser <> "") {
close table row
}
open new table row
display user id
}
display group_id
prevuser = user_id
}