Syncronizing entries in a table according to a user array in MySQL -


I have the following status entries in a table come from the list of users for a specific ID. In this way there are 3 rows in ID 7, say, 2, 6, 7 (these three are the unique IDs for the user data table). The table looks like this to clarify.

  ID USERID keyboard  

where the key is auto_inc and is the primary key of the table.

These entries come from a multiple selection field. Users may want to delete user 2 and add user 8. Therefore, the function requires updating the table, array 8,6,7 for ID 7. As soon as I can get to synchronization, it is to delete every entry, add 3 new entries in the table for ID 7 and in the table (7, 8) (7, 6) (7, 7).

Although I do not know that this is what it is supposed to be. Is there a better way? Apart from this, the key to this method actually runs fast (basically, for each modification in the table). Is this the problem? I am a newbie with these things, so please be patient.

OK, you can delete selected rows like this:

 < Remove from code> my_table where the user has 1 = 7 and the user does not have 2 (8,6,7)  

where (8,6,7) pairs (7,6), (7 , 8), (7, 7), which should be preserved, kept, should not be removed, and it will remove all other joints (7,?)

Your next question may be "How to add pairs while not duplicate again?"

You first need to teach your table which is doubling. By adding a unique key to the pair of fields (user 1, user2). Now it will refuse duplicates. Now, when inserting new lines that may already be there, then use "INSERT IGNORE" to ignore such exceptions and just continue.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -