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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.