MDanz Posted April 16, 2010 Share Posted April 16, 2010 i have a forum, with new posts how do i use sessions for each user to determine if the posts clicked on and not? I'm guessing sessions because that is individual to the user... e.g. new post, then click on not new post. i can't assign this to the actual post or then it would display as not new post for other users that haven't seen it. any tips? Quote Link to comment Share on other sites More sharing options...
deanlearner Posted April 16, 2010 Share Posted April 16, 2010 If you want the site to know if a user has accessed a topic over multiple visits, you will need to store this information in a database. If indeed it is only for the current session (that is, a single visit to the site) you can store it in a session and I'd do something like this... Each time a user accesses a topic $_SESSION['viewed'][$TOPIC_ID]=1; And on the list of topics, for each topic check... if(isset($_SESSION['viewed'][$TOPIC_ID])){ // This topic has been viewed }else{ // This topic has not been viewed } Quote Link to comment Share on other sites More sharing options...
arbitter Posted April 16, 2010 Share Posted April 16, 2010 An easyer way to do something similar is to place a cookie at the last visit, and all posts after that visit are 'new'. Ofcourse this isn't what you want, but it's a possibility. With Sessions you always have to store it in a database; otherwise it will be lost information after the user closes his browser. Quote Link to comment Share on other sites More sharing options...
MDanz Posted April 16, 2010 Author Share Posted April 16, 2010 If you want the site to know if a user has accessed a topic over multiple visits, you will need to store this information in a database. If indeed it is only for the current session (that is, a single visit to the site) you can store it in a session and I'd do something like this... Each time a user accesses a topic $_SESSION['viewed'][$TOPIC_ID]=1; And on the list of topics, for each topic check... if(isset($_SESSION['viewed'][$TOPIC_ID])){ // This topic has been viewed }else{ // This topic has not been viewed } how would i store it in a database though.. i'd have to log ever post to each username? .. or is there another way? Quote Link to comment Share on other sites More sharing options...
deanlearner Posted April 16, 2010 Share Posted April 16, 2010 I've never really worked with any forum software, but I imagine you would need another table (lets call it viewed_topic) that stores the topic id and the user id so each time a user accesses a topic, you add to the viewed_topic table a record for the user_id and the topic_id and make reference to that. Quote Link to comment Share on other sites More sharing options...
MDanz Posted April 16, 2010 Author Share Posted April 16, 2010 I've never really worked with any forum software, but I imagine you would need another table (lets call it viewed_topic) that stores the topic id and the user id so each time a user accesses a topic, you add to the viewed_topic table a record for the user_id and the topic_id and make reference to that. thx thats what i thought, but it would take up too many records. Quote Link to comment Share on other sites More sharing options...
deanlearner Posted April 16, 2010 Share Posted April 16, 2010 I don't think you should worry about record numbers, honestly. I don't know the details but a paragraph of text in a database is worth 1000's of records that store three numbers. Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted April 16, 2010 Share Posted April 16, 2010 It can't be done with sessions as such. What happens is.. you click on a thread/post, you reply. This subscribes you to it (NOT VIA SESSIONS.. AS THIS'LL EXPIRE) When a new post is submitted, it inserts the info into the database, this is where you email everyone subscribed to this post.. that there is a new reply. You could then have a table called "new_posts" This will consist of.. id, thread_id, user_id. When a post is sent, it inserts a row into this table.. well, .. a row for each user subscribed to the thread. If you have a page to check for new posts. Like this forum does, then you'd check for all rows with the current logged in user_id. Then display thread related to the thread_id on that row. When you click on the post.. if there is your user_id, with that thread_id in the database, to remove it. As you've viewed it. That's all really. You'll need extra pieces so you don't duplicate rows or anything. 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.