Is your suggestion to first clear the accessrights-table for the album being edited, and then entering a albumid/userid combination for each member who's checkbox is being checked?
Basically yes. If you remove all rights for the given conditions and then add back the new ones - much simplier than trying to work out which ones have changed etc.
Although I suspect you're going to run into problems either way, because at some point you are going to have a huge list of albums and a huge list of members so to display checkboxes for all of them will be a big page!
See you can generate the list of possible rights from your rights table, joined with the existing rights to get whether they are current or not e.g. for a given album, CurrentAlbum
Code:
select Name, isnull((select 1 from AccessRights where MembersId = Members.Id and AlbumId = CurrentAlbum), 0) as GotRights from Members
delete from AccessRights where AlbumId = CurrentAlbum
{Obtain the list of CurrentMembers from the checked boxes for this album, build that up in code so that you have a list for the following insert statement.)
insert into AccessRights (AlbumId, MemberId) select CurrentAlbum, CurrentMembers
Hope this helps. This is for SQLServer - can't promise it works for MySQL.
Bookmarks