Reputation: 4114
I created a notifications table. From that table i'm able do display the last notifications.
I'd like to actually display only the new notifications for the user if he hasn't seen it.
So i was thinking about adding one more column in my table "viewed" and set 1 once it has been viewed (when the bell is clicked). But this will set viewed for all the users ...
I'd like to ask advises about what would be the best way to do so?
Should i create a column "user_id" that would store a string of id that has already viewed the notification? ".1., .3., .17."
Or create another table with columns "id, user_id, notification_id, viewed"
If you have any other solutions, please feel free to advise it to me.
PS : Notifications will be reloaded when the page is loaded, ajax is not required.
Upvotes: 0
Views: 86
Reputation:
Create another table for user_viewed_notifications and have it be simply two columns the notification_id and the user_id and make them a paired key.
create table user_viewed_notifications(
user_id int unsigned not null,
notification_id int unsigned not null,
primary key (user_id,notification_id)
);
This will give extremely fast lookups without bogging down other joins or tables, and it's all indexed without extra information.
Upvotes: 3