CoffeeAddict Posted July 18, 2012 Share Posted July 18, 2012 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? Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 18, 2012 Share Posted July 18, 2012 Write it out in pseudo code, then translate. Are you already storing the last time the user was active? (You'll have to do that on every page load, btw) Quote Link to comment Share on other sites More sharing options...
CoffeeAddict Posted July 18, 2012 Author Share Posted July 18, 2012 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 18, 2012 Share Posted July 18, 2012 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. Quote Link to comment Share on other sites More sharing options...
CoffeeAddict Posted July 18, 2012 Author Share Posted July 18, 2012 That makes perfect sense, thank you! Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 18, 2012 Share Posted July 18, 2012 No problem. Quote Link to comment Share on other sites More sharing options...
xyph Posted July 18, 2012 Share Posted July 18, 2012 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 18, 2012 Share Posted July 18, 2012 xyph, how would you do it, more like my original suggestion? Or have a separate table for the messages/clicks? Quote Link to comment Share on other sites More sharing options...
xyph Posted July 18, 2012 Share Posted July 18, 2012 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.