Best way to show admin message to specific users?

I am creating a social networking site in PHP / MySQL / jQuery. When a user logs in to my site, I would like to query the database and get an admin announcement, if one exists. This will be a message box that appears on the page to all users, but it will have an X to click on it, and not show it again until the administrator publishes a new advertisement. Therefore, if you never click on X, and there are announcement messages that exist in db, it always displays this message box on your page, however, if you did cli9ck X to close the window, you will return to the page on which it will not exist unless a new admin message is posted.

I know that there are several ways to do this, but I'm looking for the most efficient way.

One of my ideas is, if I add an additional mysql field to the user table "admin_message" and mark it as 0, then when I publish a new administrator message, it will change the entry for each user to 1, if the administrator message is set to 1, then he displayed on the user page. Then, when the user presses the X button to hide the field, he will update the user table row there and change the value to 0.

Another idea that I have is to use a cookie to check if the user has chosen to hide the message, I think it will be faster, but maybe not so good, since the user can log in with different computers and if a new one is displayed message, they may not see it right away.

So I'm just wondering if it's worth using an extra database field? If I had 1,000,000 users when I sent a new admin message, I would need to update 1,000,000 lines so that everyone could see this message. Is there a better way? Also, as soon as the user logs into my site, I will use the session to store the value that they see or hide the message, instead of looking at the database every time the page loads.



UPDATE

Sorry, I think that my post could be a little confusing or incomprehensible in what exactly I had in mind, because most of the answers are satisfied using a message system in which it is not so close.

, , . , 1 , , . 1 , 2352345234 , , 1 , .

, "div" , , .

, "" "" .

, , , , , , , .

+5
5

:

. cookie , , , , , . , cookie. : . : , cookie .

: - ( , ). , 1) cookie , 2) , 3) , . , cookie/ . : . : , db.

: , , , , .

+3

last_message_seen, "" (message_id > last_message_seen) . [X] ( -), javascript ..

, javascript, () / , , , .

... , . , "" , : ( - 1 ) - ...

+1

№1. bool-, , , datetime . == , . NOW().

, , .

EDIT:

, . , , . X ( ), db .

, .

- messahe, , , .

EDIT2: :

, . , , , , 100 000 - 100 000 X, , , ,

- . "show/not show" , . , , ? , ( ), , .

+1

? last_login datetime?

, , date_created >= last_login. , last_login now().

+1

admin_message_queue. , . , - . , , admin_message_queue, = .

, , AJAX , . admin_message_queue, = , , - . , - .

. , -? , .

: , , . . , . , , , , (, ), . , .

0

All Articles