Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sites to help me create tag in PHP (like the tags on this site)

Tags:

php

tags

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.

like image 457
ggfan Avatar asked Dec 17 '22 02:12

ggfan


2 Answers

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!

like image 56
Sampson Avatar answered Feb 22 '23 23:02

Sampson


You might look at this project for inspiration and ideas, http://alexking.org/projects/php-tag-engine

like image 26
Chris Wagner Avatar answered Feb 23 '23 00:02

Chris Wagner