帮助我在 PHP 中创建标签的网站(如本网站上的标签)

编程入门 行业动态 更新时间:2024-10-06 13:22:00
本文介绍了帮助我在 PHP 中创建标签的网站(如本网站上的标签)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-05-01 10:38:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1408594.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标签   我在   本网   站上   网站

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!