Vay*_*Vay 2 php mysql facebook
我想做一个Facebook类似的通知系统,但我想不出方法,如何实现它.
我在这里读到了各种各样的意见,比如有一张桌子,其他人说要有两张.
然而,我正在尝试最有效的方式,只有neccesarry数据条目.notfication到目前为止这是我的表:id,uid,type,read(boolean),date.
所以我想到了一个例子:
插入注释,调用通知函数,插入我的uid(user_id),键入(注释,类似等),read ='1',NOW().
我将读取设置为1,因为我不想在发布内容时收到通知.然后我想我会notification通过所有其他用户将读取设置为0来更新,因为他们还没有读过这篇新帖子.
但是现在我想到的是另一篇文章,将在5秒后发布或者其他内容.然后所有其他read条目再次设置为0,这是正确的,但在这种情况下,我想不出为每个单个用户显示(SELECT)正确的结果.因为没有指定哪个用户错过了哪个新通知.
我希望你能跟着我并提出任何建议.如果我以错误的方式做到这一点,我也会感谢建议.
首先,您必须知道您的通知是否适用于您的所有用途,或者可以是特定于用户的.在Facebook的情况下,我会说这是第二种选择.
我的第一个建议是找到一个实现这个功能并查看其代码的开源项目(或者甚至可能是2个).
我的第二个建议是写下此功能的所有要求,通常,一个小的限制可以引起对表结构的修改甚至添加新表(例如,可以向多个用户发送通知一次?用户可以向另一个用户发送通知吗?...).
这是我的方式,使用2个表,一个用于消息,一个用于与用户的NtoN关系: 表通知
ID // auto increment ID
sender_id // Can be a subsystem or another user. To be defined / optional. Does not have to be a foreign key.
title // Title of the notification
body // The text message
type // warning, message, error or any notification class you can think of
... // you can add other options, like priority, attachment...
Run Code Online (Sandbox Code Playgroud)
表Notification_User
notification_id // Foreign Key for the notification
receiver_id // Foreign Key for the user
is_read // is the notification read
is_deleted // is the notification deleted, this implements a Trash bin like feature
created_at // time at which the notification was sent
read_at // time at which the notification was read
deleted_at // Time at which the notification was deleted
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2642 次 |
| 最近记录: |