问题描述
限时送ChatGPT账号..我正在尝试学习如何在 PHP/MySQL 中创建标签.有谁知道一些有助于解释如何创建标签的好网站?
标签就像您在 stackoverflow 中提问时看到的标签一样.
解决方案一个非常简单的例子是拥有三个表:
<前>+--------------------+ +--------------------+ +---------------------+|标签 ||问题 ||问题标签 |+--------------------+ +--------------------+ +---------------------+|+ 标签 ID ||+ 问题 ID ||+ 问题 ID |+--------------------+ +--------------------+ +---------------------+|+ 标签名 ||+ 问题标题 ||+ 标签 ID |+--------------------+ +--------------------+ +---------------------+|+ 问题文本 |+--------------------+您可以在标签表中包含所有标签:
<前>+---+---------+|1 |PHP |+---+---------+|2 |C# |+---+---------+问题表中的问题:
<前>+---+-------+--------------------+|1 |标签?|我如何制作标签.|+---+-------+--------------------+然后通过它们的 ID 将它们关联到 QuestionsTags 表中:
<前>+---+---+|1 |1 |+---+---+这会将标记 1 与问题 1 一起放置.您可以插入另一行以将另一个标记添加到问题 1.现在要获取问题的所有标记,您可以根据问题 ID 进行搜索来查询 QuestionTag 表.要获取标签的所有问题,您可以根据标签 ID 查询 QuestionTag 表.
祝你好运!
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!
这篇关于帮助我在 PHP 中创建标签的网站(如本网站上的标签)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论