I am not really sure if i understand it right that you want to use the tags on topics For this explanation i will use tags on topics.
Create a table Topics with the columns you like but also with a primary key column:
- topicID (integer, primary key, autoincrement)
…
Create a table tags with two columns:
- tagID (integer, primary key, autoincrement)
- name (varchar(64))
To couple MANY tags to MANY topics you will need a JOIN table with two columns:
- topicID (integer, primary key)
- tagID (integer, primary key)
Now you will be able to add Topics to the topic Table, to add Tags to the tag table and to couple tags on topics by adding a topicID and tagID to the JOIN table which you best can call topic_tag.
Now when you show a topic and you would like to get all tags related to this topic you could write a SELECT query with a JOIN:
SELECT tag.tagID, tag.name FROM tag
JOIN topic_tag ON tag.tagID = topic_tag.tagID
WHERE topic_tag.topicID = ?
Or get the topic and all related tags in one time:
SELECT topic.topicID, topic.title, tag.tagID, tag.name FROM topic
LEFT JOIN topic_tag ON topic.topicID = topic_tag.topicID
LEFT JOIN tag ON tag.tagID = topic_tag.tagID
WHERE topic.topicID = ?
I used LEFT JOINs so that even if a topic do not have a single tag you still get the topic data. tag.id and tag.name will be NULL in that case.