0

How would I go about writing up a basic tags feature? (similar to the one on this site)

I'm struggling coming up with good logic with little redundancy and would like a more experienced programmer's take on this.

The site I have is fully developed as of right now and has a search feature (searches through titles) - I'm just looking to expand on this and allow the search to sift through tags as well.

Edit:

I was considering adding a row on to my main table called "tags". Then separating them by spaces.

But I have also thought about create a new table and using the same id's from my main table, creating tags in this manner.

2
  • 2
    With respect that you're asking of guidance, what have you tried so far? Commented Oct 17, 2011 at 17:02
  • Simply have a tags table with a foreign key for your titles? Commented Oct 17, 2011 at 17:05

1 Answer 1

2

I'd suggest 2 tables. One contains Tags - the name of the tag, a tag id, any anything else you want to keep track of on a tag. Also create a relationship table that connects your article/post id to the tag id. You won't repeat data in the database, you should be able to search the tags and join tables together to come up to return articles, and also query the tags if you want to display them along with posts.

Sign up to request clarification or add additional context in comments.

1 Comment

Using the relationship table is a great way to do it because it allows you to have an index on the individual tags while efficiently joining to the content table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.