douya2982 2014-04-29 01:16
浏览 40
已采纳

在MySQL中存储用户通知的最佳方法是什么?

I am building a noticeboard module in a php/mysql app. The idea is an admin can post notices to a single user, groups of users (by role), perhaps combinations of users/groups/roles, everyone in the system.

My initial thoughts were to have the following schema which solves my send to a single user or single user role:

notices
----------------
notice_id
notice_date
notice_title
notice_text
notice_recipients  <-- linked to user_role_id (from user_roles table)

I'm not sure how to record 2 groups and/or 50 individual recipients without having duplicated rows in the database. Is it possible to store all the user_role_id's in the one notice_recipients field and then somehow read the contents of that field to display in each individual users noticeboard?

  • 写回答

1条回答 默认 最新

  • dpp78272 2014-04-29 01:19
    关注

    You need a join table:

    notices
    ----------------
    notice_id
    notice_date
    notice_title
    notice_text
    

    and

    notices_users
    ----------------
    notice_id
    user_id
    

    When you create a notice, write it to the notces table. Then for every user, that should receive it, add a row to notices_users. If you have shown it, either delete it from notices_users or add a status field.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料