许多表 - PHP / AJAX通过复选框处理

To be specific, I've got a table for photos, one for tags and one for the relationship between these two.

I'd like the many-to-many relationship table to be updated through AJAX via a form using checkboxes. I'm using a PDO wrapper to handle MySQL queries ,though I'm not really sure what to do with the received $_POST data in PHP.

I would like to use a single query to sort out the table, I just haven't found an example how to deal with it. For example, let's say I receive a POST like the following:

array(2) {
    ["photo-tag-id"]=> string(3) "220"
    ["photo-tag"]=> array(2) {
        [25]=> string(2) "25"
        [26]=> string(2) "26"
    }
} 

I have to check if an association already exists (because the form might contain values of checkboxes already checked and saved), have to check if the POST contains unsaved id pairs (those need to be inserted), and I also have to check if the table contains any pairs which the POST doesn't (this happens when a checkbox gets unchecked - so association needs to be deleted).

I could of course delete all rows where the 'photo-tag-id' matches then just insert all the received values, but I'm just not sure if that qualifies as a best practice, and I'm always keen on learning some new, cooler methods as being a beginner.

Sorry for overexplaining stuff, hope it's understandable what I'm trying to accomplish here :)

So, have you got any suggestions on this, please?