If I have a tag system like Stackoverflow. I can add tags, save and after delete a tag, or add new tags.
For example, initially:
PHP, JQUERY, ARRAYS
save question and publish,
I changed my mind, and I will delete JQUERY, so I edited my question to only two tags:
PHP, ARRAYS
My question is: what is the best way to remove the tag from database after inserted?
I need to check which tag is removed.
Any idea? Thanks!
To clarify the problem:
i have a many- to -many table
$first = array (php, jquery, arrays)
question1 | php
question1 | jquery
question1 | arrays
after edited, i will have (the goal):
$first = array (php, jquery)
question1 | php
question1 | jquery
to add new tags is easy. Unique constrain, and a foreach solves the problem.
But to remove tags. I need to remove the specific tag arrays from the junction table.
the question is how ?
so, i have this array: $first = array (php, jquery)
and this table structure (THIS IS THE PROBLEM):
question1 | php
question1 | jquery
question1 | arrays
This is best implemented as a many-to-many relationship.
You do this by using a junction table. For example
To remove a tag for a question, simply delete the record from the
QUESTION_TAGtable, egUpdate
Your best bet is to make tag removal a capture-able event. What I mean by this is that each removal is handled in a way so you are able to capture the tag to be removed.
Another approach is to remove all
QUESTION_TAGentries for the question and re-insert the tags to keep.