I am trying to learn how to create tags in PHP/MySQL. Does anyone know some good sites that help explain how to go about creating tags?
Tags as in the tags you see when you ask a question in stackoverflow.
A very simple example would be to have three tables:
+---------------------+    +--------------------+    +---------------------+
| Tags                |    | Questions          |    | QuestionTags        |
+---------------------+    +--------------------+    +---------------------+
| + TagID             |    | + QuestionID       |    | + QuestionID        |
+---------------------+    +--------------------+    +---------------------+
| + TagName           |    | + QuestionTitle    |    | + TagID             |
+---------------------+    +--------------------+    +---------------------+
                           | + QuestionText     |
                           +--------------------+
You can have all of your tags within the tags table:
+---+---------+ | 1 | PHP | +---+---------+ | 2 | C# | +---+---------+
Your questions within your questions table:
+---+-------+---------------------+ | 1 | Tags? | How do I make tags. | +---+-------+---------------------+
And then associate them in the QuestionsTags table via their ID's:
+---+---+ | 1 | 1 | +---+---+
This places tag 1 with question 1. You can insert anther row to add another tag to question 1. Now to get all tags for a question, you query the QuestionTag table basing your search on the question ID. To get all questions for a tag, you query the QuestionTag table basing your search on the tag ID.
Good luck!
You might look at this project for inspiration and ideas, http://alexking.org/projects/php-tag-engine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With