how can i create a tagging system using php and mysql?(如何使用 php 和 mysql 创建标记系统?)
问题描述
想知道如何在 php 和 mysql 数据库中创建标签系统,我最初的想法是在存储文章的表中创建一行,命名标签,并列出用逗号分隔的标签,但我是不知道如何创建一个搜索匹配标签的查询,我不想每次有人点击标签时都查询每篇文章.谁能帮忙?
wondering how i can create a tagging system in php and with a mysql database, my initial thoughts were to create a row in the table where the articles are stored, named tags, and list the tags seperated by commas, but i am not sure how i can create a query that searches for matching tags, i dont want to have to query every article everytime someone clicks a tag. can anyone help?
推荐答案
您正在描述文章和标签之间的多对多关系.您可能希望使用中间联结表来解决这种关系.
You're describing a many-to-many relationship between Articles and Tags. You'd want to use an intermediate junction table to resolve that relationship.
现在,要查找与所选标签匹配的所有文章:
Now, to find all articles that match a selected tag:
SELECT a.article_title
FROM Tag t
INNER JOIN Article_Tag_Xref atx
ON t.tag_id = atx.tag_id
INNER JOIN Article a
ON atx.article_id = a.article_id
WHERE t.tag_name = 'SelectedTagName'
这篇关于如何使用 php 和 mysql 创建标记系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 php 和 mysql 创建标记系统?
基础教程推荐
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何替换eregi() 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
