Often have this experience, is to log on a system, there will be a system message, and this message is for everyone, then how the program is to distinguish who has seen the news who have not seen it? (because the person who has not seen will have a hint always hangs in the page head, and the person who has seen this hint will automatically disappear), how does this effect with PHP how to do, data structure is how to design?
Reply to discussion (solution)
First you have to have a list of messages that have a read field in it.
First you have to have a list of messages that have a read field in it.
If there are 100,000 users, some have seen some have not seen, this field how to mark Ah?
Who sent this message, and who is sent to the table also need to record Ah, so you can according to each user's user ID to read the personal message
Table structure
Table1:message
msg_id msg_content Publish_time
Table2:read
msg_id user_id Read_time
Publish a system message insert a record in message
Such as:
123 "Afternoon Break" 1414468731
People who have seen insert a record in the Read table
123 5145 1414468745
Determine if there is unread information
SELECT * from message where msg_id not in (select msg_id from read where user_id = 5145)
If you are interested in SQL efficiency, you can use the following
SELECT * from message where message left join (select* from read where user_id = 5145) temp on message.msg_id = temp. Msg_ ID where temp.user_id is null;
Table structure
Table1:message
msg_id msg_content Publish_time
Table2:read
msg_id user_id Read_time
Publish a system message insert a record in message
Such as:
123 "Afternoon Break" 1414468731
People who have seen insert a record in the Read table
123 5145 1414468745
Determine if there is unread information
SELECT * from message where msg_id not in (select msg_id from read where user_id = 5145)
If you are interested in SQL efficiency, you can use the following
SELECT * from message where message left join (select* from read where user_id = 5145) temp on message.msg_id = temp. Msg_ ID where temp.user_id is null;
Thank you for your detailed reply, this way I have also considered, but if the system message released more, plus a large number of users, this kind of operation database is very large, if there are 10W users, see a system message there are 10W records, there is no easier way?
Who sent this message, and who is sent to the table also need to record Ah, so you can according to each user's user ID to read the personal message
This is for everyone, so this push mode is not appropriate.
Table structure
Table1:message
msg_id msg_content Publish_time
Table2:read
msg_id user_id Read_time
Publish a system message insert a record in message
Such as:
123 "Afternoon Break" 1414468731
People who have seen insert a record in the Read table
123 5145 1414468745
Determine if there is unread information
SELECT * from message where msg_id not in (select msg_id from read where user_id = 5145)
If you are interested in SQL efficiency, you can use the following
SELECT * from message where message left join (select* from read where user_id = 5145) temp on message.msg_id = temp. Msg_ ID where temp.user_id is null;
Thank you for your detailed reply, this way I have also considered, but if the system message released more, plus a large number of users, this kind of operation database is very large, if there are 10W users, see a system message there are 10W records, there is no easier way?
Haha, think about Redis.
10W user needs 15K memory mark whether the user sends each message is 15K
1. Read Message setbit msg_123 5415 1
2. Determine whether to read Getbit msg_123 5415
The message table has content and UserID, and if userid=0, indicates that the message is global
In the user table, you can add a field record to view the message ID, separated by commas, such as 1,20,123
I've seen one. Add a message ID
If the message is more frequent, consider maintaining a single message to view the record table, only the UID MsgId two fields, the record is viewed
Get a watch and put the people you've seen in the bag???
If you don't find it, show it to him.
Table structure
Table1:message
msg_id msg_content Publish_time
Table2:read
msg_id user_id Read_time
Publish a system message insert a record in message
Such as:
123 "Afternoon Break" 1414468731
People who have seen insert a record in the Read table
123 5145 1414468745
Determine if there is unread information
SELECT * from message where msg_id not in (select msg_id from read where user_id = 5145)
If you are interested in SQL efficiency, you can use the following
SELECT * from message where message left join (select* from read where user_id = 5145) temp on message.msg_id = temp. Msg_ ID where temp.user_id is null;
Thank you for your detailed reply, this way I have also considered, but if the system message released more, plus a large number of users, this kind of operation database is very large, if there are 10W users, see a system message there are 10W records, there is no easier way?
Haha, think about Redis.
10W user needs 15K memory mark whether the user sends each message is 15K
1. Read Message setbit msg_123 5415 1
2. Determine whether to read Getbit msg_123 5415
Thank you again for your help!
The message table has content and UserID, and if userid=0, indicates that the message is global
In the user table, you can add a field record to view the message ID, separated by commas, such as 1,20,123
I've seen one. Add a message ID
If the message is more frequent, consider maintaining a single message to view the record table, only the UID MsgId two fields, the record is viewed
nn This can be considered, at present, the only way to make it easier.
If you don't find it, show it to him.
Well! You can try this.