Try adding a third column to the table, which would act as the primary key. In this column, you would insert the concatenated values of the user id and the group id. That way, you can never enter the user twice with the same group. For example:
table:
create table groups(id int(12) not null, uid, int (12) not null, group int(12) not null, primary key(id), key users(u_id));
Then, whenever you insert into the table, you would provide three values
id = $uid . $grp_id
uid = $uid
group = $group
And there you have it. I hope that helps
-Chris