I have a mysql db with an article (article_id, keyword) db table where keywords is a comma-separated list. I have created two new empty tables:
keywords (keyword_id, keyword) where each row has only one keyword.
article_key (article_id, keyword_id) where each row has only one keyword.
Thus I want to have a many-to-many relationship from articles to keywords. I wanted to create a short script to extract the id and keywords from the original article table, split the keywords and populate the two new tables appropriately. I assumed this would be easy, but has proved a little more tricky than I thought.
Any help would be much appreciated.
You could do something similar to this:
In this script (not tested) I assumed you already have your keywords table filled with the keywords, and that your article table contains a comma seperated list of KEYWORDS and NOT id’s.