如何在数据库中保存标签(关键字)? [英] how to save tags(keywords) in database?

查看:731
本文介绍了如何在数据库中保存标签(关键字)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用php和mysql创建一个简单的标签系统,以便用户可以通过表单添加一些标签.我的问题是我应该将标签保存为单个数据库列中的数组吗?例如. "tag1,tag2,tag3" ..或我应该在数据库表中具有单独的列,我应该将每个标签保存在每一列中. 我希望我的问题清楚. 谢谢.

I want to create a simple tags system using php and mysql, so that users can add few tags via form. My question is that should i save the tags as an array in single database column? eg. "tag1, tag2, tag3".. or i should have separate columns in database table where i should save each tag in each column. i hope my question is clear. Thanks.

推荐答案

我可能都不会说.在标记和被标记的对象之间使用多对多关系.例如,如果被标记的东西是一个问题,则表可能看起来像这样:

I would probably say neither. Use a many-to-many relationship between tags and the object being tagged. For instance, if the thing being tagged is a question, the tables could look like this:

Question:
    QuestionId
    Title
    Body

Tag:
    TagId
    Name

QuestionTags:
    QuestionId
    TagId

这篇关于如何在数据库中保存标签(关键字)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆