Jump to content

Notification bar only when database is updated


CoffeeAddict

Recommended Posts

I'm trying to add the following CSS notification bar to my site to notify the user when the news is updated.

http://deepubalan.com/blog/2012/02/14/notify-pure-css-notification-bar-using-target-pseudo-class/

 

I cannot wrap my brain around how to make it show up only when an update has been made to the database since the user's last visit. Obviously if the user has already seen the news I don't want to keep showing the bar. When I make a news post the time is recorded in the database, so I'm assuming I need to check the user's last visit time, compare that to the time the last news was posted and then display or not display the bar? And somehow I need to check if the user has clicked the bar or not...

 

That seems like the logical way, but I don't know where to start writing the actual code. Help please?

 

 

Link to comment
Share on other sites

Thanks for your reply! The user's last log in time is recorded but not their last active time on each page load. I'll probably end up using the last log in instead.

 

Check the user's last log in time

Check the news latest update time

if the user's log in time is after the news time, display the bar

 

That's as far as I've gotten when it comes to psuedo code, and even then I have a hard time translating it. I'm pretty new to php

Link to comment
Share on other sites

So you want it to be something they have to click to clear? Create a column in the user table called "read_latest_news". When you update the news, set everyone to 0. If a user logs in and has a 0, display the news. When they click it, set theirs to 1.

 

Link to comment
Share on other sites

Keep in mind this isn't a very scalable solution (slows down with a large userbase). Assuming you don't post news very often (say, once a day), and plan on having less than 50,000 rows in your user table, it's the easiest to implement.

Link to comment
Share on other sites

Your original suggestion, using last active dates compared to the news date...

 

If I wanted the 'fresh news' notification to appear until the actual news page was visited, I'd keep track of the last time the user visited the news page as well. That way, you can still simply compare dates, rather than having to modify a huge number of rows in a table on news posting. It does make the user table a little bigger though.

 

For a small implementation, it really doesn't matter. I was being a little anal in my reply. Unless you're having problems keeping your user table in memory, resetting the flag should be nearly instantaneous.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.