counting number of new entries in guest book
I want to display the number of new(unseen) guest entries in the guest book of a user. I was thinking to count it so that, total number of entries in guestbook minus entries in guestbook at time of last login. However, I think that is not a good approach, because if the user logs in but does not go to his guestbook, in that case, the entri开发者_StackOverflow社区es should be still "new", also if some new entry is posted in the user while he is online, it does not work in that case too. Any suggested please?
You could save the time when the user last entered the guestbook, and display the number of new entries since that time.
You can have a column which indicates when entry is marked as seen/unseen and group the total number of entries on this column.
Edit after reading the comments: if your messages have an autoincrement id column you may save the max id of the unseen entries in the guestbook when the user visits the book. Initially it would be zero. Further a "new" entry will have an id > of the saved max id. If this is not the case you may consider using timestamps - the last time the user entered the guest-book compared to the message timestamp. I believe that the messages should have at least timestamp.
The question sounds too general to me. but you probably need to have a flag per entry; it gives the client the opportunity to set some entries to unseen, if he wants.
精彩评论