I've got a form that allows the user to edit an employees information: name, email, technician level, etc. Well this is not hard in itself, I'm trying to find a good method for updating phone numbers for each employee. I have two tables (that are relevant): technicians and phones. My form allows the user to add, remove and edit any amount of phone numbers for the employee they are currently editing.
I'm not quite sure how to balance the updating of the phones table between PHP and JS (note this app is AJAX intensive).
I'm thinking I can either:
- Use JS to track which phone numbers need to be updated, which need to be added and which need to be removed and then either send that data to a single PHP script or call three different PHP scripts.
- Let PHP figure it out. Send a script the list of the phone numbers the technician should now have. I could then either: delete the technicians old phone numbers and insert the new set, or query the database for the old numbers and compare them one by one to the new list.
What would a common method of accomplishing this kind of task be (I'm sure this problem doesn't apply to only my situation). After typing it out, it seem to me the simplest way would be to just delete all the old rows for that technician and insert the new ones.