User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Database Design section within the Web Development category of DaniWeb, a massive community of 428,574 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,608 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Database Design advertiser: Programming Forums
Views: 1187 | Replies: 2
Reply
Join Date: Apr 2007
Posts: 2
Reputation: aarnott is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
aarnott aarnott is offline Offline
Newbie Poster

Storing if a user has viewed a post

  #1  
Apr 4th, 2007
I'm making a forum-like program, and I'm having difficulty designing a particular feature. I want it to store if a user has viewed a particular post or not. I'm not sure exactly how to go about this. What do you think would be the best approach?

Thanks,

Andrew Arnott
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2007
Location: India
Posts: 2
Reputation: nitinmms is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
nitinmms nitinmms is offline Offline
Newbie Poster

Re: Storing if a user has viewed a post

  #2  
Apr 5th, 2007
Hi,

Well this is a possible solution:

1. Make a Table say tblForumView with
Following fields:
ID
UserId
lastVieweddate

1. On Login Page, store the User's ID (UserId) in a Session Variable.

2. On the Forum Page in the Page Load Event, check if this userID exists in tblForumView table by saying something like
select count(*) from tblForumView where
userId=Session("UserId")

Now, if the above query returns 0 then this userId has not made any views of this page.
So you insert a record for this userId in the table tblforumview.
On the other hand , if count>0 then this UserID has visited eralier, so just update the
field [lastVieweddate] with current date and time.

Storing a [lastVieweddate] will allow you to remind the user as to when he last visited the page.
And also enable you to do some other cool things like for example,

You can display Alll the New Posts which have been posted since his last visit to the forum.

Regards,

Nitin
Reply With Quote  
Join Date: Apr 2007
Posts: 2
Reputation: aarnott is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
aarnott aarnott is offline Offline
Newbie Poster

Re: Storing if a user has viewed a post

  #3  
Apr 5th, 2007
Originally Posted by nitinmms View Post
Hi,

Well this is a possible solution:

1. Make a Table say tblForumView with
Following fields:
ID
UserId
lastVieweddate

1. On Login Page, store the User's ID (UserId) in a Session Variable.

2. On the Forum Page in the Page Load Event, check if this userID exists in tblForumView table by saying something like
select count(*) from tblForumView where
userId=Session("UserId")

Now, if the above query returns 0 then this userId has not made any views of this page.
So you insert a record for this userId in the table tblforumview.
On the other hand , if count>0 then this UserID has visited eralier, so just update the
field [lastVieweddate] with current date and time.

Storing a [lastVieweddate] will allow you to remind the user as to when he last visited the page.
And also enable you to do some other cool things like for example,

You can display Alll the New Posts which have been posted since his last visit to the forum.

Regards,

Nitin


Thanks for the reply -- great idea. I have to do something slightly different however. I need to know exactly which pages have not been viewed (rather than just showing which have not been viewed since the last visit). Here is my current idea... I'm not sure if it is a bad idea or not though.
  • Have a bigtext type field int the user table called viewed_posts.
  • In php I will have a session variable called 'viewed_posts' or something similar to that effect --> it will be a serialized array
  • When the user logs in, it will take the database version of viewed_posts and store it in the session variable.
  • When they visit a page, viewed posts will be deserialized into an array and I can work with it from there.
  • When they veiw a new post, I just add that post ID to the array, serialize it, store it in both the session and the database.
Again I'm not sure if this is going to be horribly inneficient, or if there is a better option. I was thinking a linker table might work, but that could get hairy if there are huge numbers of users (I'm not sure how slow searches would get).

Thanks for taking a look!

Andrew Arnott
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Database Design Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Database Design Forum

All times are GMT -4. The time now is 11:18 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC