doukunsan5553 2012-10-11 20:29
浏览 32
已采纳

如何用PHP和MySQL的逗号分隔标记系统获取相关帖子? [关闭]

I'm creating a website using PHP and MySQL to post related sites. I'm using a tagging system for this site with comma separated tags, for example my tags will look like: php, mysql, code, programming.

The reason I use this comma separated tagging system is because I want the user to be able to insert any kind of tag he wants for his post.

I have searched from this site and internet, but the answer is not really relevant to my question. Many tagging system use three table like item, tag_map, and tag, and I think it doesn't work for comma separated tagging system.

So far, I have already create a table with name and tag fields in it. The best solution I have found is using Tf–idf, term frequency–inverse document frequency to weight the post relative to its content.

Are there any other good solutions for this? If there are not I'm really grateful if someone can explain this tf-idf example using php code.

  • 写回答

1条回答 默认 最新

  • douzen1880 2012-10-11 21:03
    关注

    This isn't the way it shouldn't be done, like the comments adressed. You should split up this in three tables:

    A table which stores the posts itself;

    Table posts
    -----------
    id
    text
    

    A table for all the tags;

    Table tags
    -----------
    id
    name
    

    And finally a table to connect the two;

    Table postTags
    -----------
    id
    postId
    tagId
    

    When selecting data from these, you can use a query like the one below:

    SELECT * FROM posts p
    INNER JOIN postTags pt ON pt.postId = p.id
    INNER JOIN tags t ON pt.tagId = t.id
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器