Faced with a seemingly standard problem, but I can't find neostyle solution (or maybe I'm just a sweet). The feeling that everything is very simple and elementary solved, and I'm not ashamed who knows nothing.
There are two tables A and B primary keys are id — surrogate standard these INT NOT NULL AUTO_INCREMENT PRIMA...
For the realization of communication "many-to-many" has a table of context, A_B, consisting of two fields: a_id and b_id — foreign key tables A and B, respectively. The primary key that seems logical, consists of this pair of foreign keys.
There are phpmygallery admin database management. In particular, the page for editing links between A and B. more specifically, the edit form all records in the table A_B with some specific a_id. The result is approximately 20 rows per page, all editable via input General submit.
PROBLEM: php script that handles the form on submit gets changed when and don't know what they were before editing, because the keys in which they are identified have changed. That is, if the user changes | a_id | b1_id | | a_id | b2_id |, the script knows what to change, but doesn't know what it was originally | a_id | b1_id |.
I started thinking to myself, found some solutions, but they do not suit me:
1) store in a hidden form field with the original values links, send them by submit and for them to determine variable entry database. Didn't like the feel of the crutch; security issues, although they generally care about the least.
2) to add to the table when another field — surrogate unchanging id, which identifies a modified contact. As in the previous paragraph, storing it in a hidden-form field. Don't like: see the previous item + the wrath of the gods relational data models; the need lapetite the structure of the database for such things.
3) change = remove + add. To clean up all 20 records and add new. Didn't like the feel of the crutch; deleting and adding multiple entries for a single change (in this case 20, in another are all 120)
talk some sense into me