views:

47

answers:

3

We currently have a message option on our site that displays any message we add via the CMS to logged in users, but what would be the best way to offer a 'hide' option? This way if that particular user doesn't want to see the message again they could hide it? Any suggestions welcome...

A: 

Assuming that you only display one message at a time, you could add a boolean column to your Users table and set it to true when the user clicks hide, then check that column before displaying the notification.

Then, every time you make a new notification, you could reset the column to false for every user.

SLaks
+3  A: 

Assuming these are notifications/updates that users need to read, try something like this:

  • When logging in, let the user know they have N new messages to read.
  • If a user goes to the messages page to read those messages, update the date with the current time in a last_read_date column on their user metadata.

Now, to decide what messages to show on a given login, just check the last_read_date column against the date of each message. If the message's date is in the future relative to last_read_date, they haven't seen that message yet.

John Feminella
I think this is the best solution yet, but only really good if the user has 1 message displaying at any one time. Could be a problem if they haven't logged in for a while and two message/notifications are displayed together, the user might click to hide the newest (which would be on top) and the one below would also be hidden, but like the overall thinking.
jimbo
A: 

you should add table to db that will link between users table and messages table

with fields:

userid , messageid , status

now when you have logged in user you just do

select * from messages where status='new' and userid='[userid_here]'

when user reades that message you just change the status row to something else like 'old'

this way you can show only the messages that user didnt read.

This will work, and has the most flexibility. But, it scales horribly: the number of records in this table will be the number of users times the number of messages.
Wim