我如何使用php和mysql创建一个标记系统? [英] how can i create a tagging system using php and 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创建一个标记系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!