Nixeon Posted September 9, 2009 Share Posted September 9, 2009 Hey Guys, Just looking for some advise. I'm creating a forum for my brothers site (it's a simple forum, as he didn't want to use phpBB or anything like that). I've got 90% of the forum complete now, however I now need to implement read/unread topic icons and I have no idea how to about working out if a topic has been read or not (since last visit?). A few ideas I had, but don't think will work are: Timestamps on all posts and useraccounts. Basically having the $post_time for the posts and a $last_active for the user, so when a user refreshes pages a function is run to update $last_active and then work out whether the last post for a topic is after the $last_active time i.e. if($post_time > $last_active) { topicUnread } however I doubt this will work because when user views a topic they will get a $last_active for the current time not when they last viewed the topic. Another idea was to have a topic_read table in the database and then put all the topics and times users visit the topics, but this doesn't seem right. surely there is a simple(well "correct") way to work out if a user has read a topic since the last post? Cheers for the help in advanced Quote Link to comment https://forums.phpfreaks.com/topic/173677-solved-creating-forums-topic-readunread/ Share on other sites More sharing options...
Zane Posted September 9, 2009 Share Posted September 9, 2009 There needs to be an activity table. For all users...Like an actions log.. things like view, edit, delete, etc, etc, that would store things like id | userId | actionId | postId | datetime | Now the complicated part ----- When you go to check if the post is read or unread you have to do your math based on a join of the activity table and the posts table...so lets see I'll have to get back to you on this one...I'm stumped on the coding part, but I got the idea down. EDIT What's the code you are using for displaying all the posts... Quote Link to comment https://forums.phpfreaks.com/topic/173677-solved-creating-forums-topic-readunread/#findComment-915540 Share on other sites More sharing options...
Nixeon Posted September 9, 2009 Author Share Posted September 9, 2009 the viewtopic.php is as follows <?php include("forum_functions.php"); include("header.php"); grabposts($_GET['t'], $_GET['f']); ?> <div id="page_container"> <div class="content_box"> <!-- START BREADCRUMS --> <div id="breadcrums"> <ul> <li><a href="index.php">Home</a> »</li> <li><a href="viewforum.php?f=<?php echo $_GET['f'] ?>"><?php grabforumname($_GET['f']); ?></a> »</li> <li><a href="viewtopic.php?f=<?php echo $_GET['f'] ?>&t=<?php echo $_GET['t'] ?>"><?php grabtopicname($_GET['t']); ?></a></li> </ul> </div> <div class="page_title"><?php grabtopicname($_GET['t']); ?></div> <div class="forum_topbar"> <?php if($topic_locked != "yes") { ?> <span><input type="button" value="Post Reply" class="button" onclick="parent.location='post.php?type=post&f=<?php echo $_GET['f']; ?>&t=<?php echo $_GET['t']; ?>'" /></span><?php if(((isset($_SESSION['CDA_Username'])) && ($_SESSION['CDA_Username'] == $row_grabposts['Owner'])) || ($_SESSION['CDA_Usergroup'] >= 2)) { ?> <input type="button" value="Lock Topic" onclick="parent.location='forum_functions.php?action=locktopic&topic=<?php echo $_GET['t']; ?>'" class="button"><?php } ?> <?php } else { ?> <span><input type="button" value="Topic Locked" class="button" disabled="disabled"/></span><?php if(((isset($_SESSION['CDA_Username'])) && ($_SESSION['CDA_Username'] == $row_grabposts['Owner'])) || ($_SESSION['CDA_Usergroup'] >= 2)) { ?> <input type="button" value="Unlock Topic" onclick="parent.location='forum_functions.php?action=unlocktopic&topic=<?php echo $_GET['t']; ?>'" class="button"><?php } ?> <?php } ?> <span class="right"><?php echo $rows_totalposts; ?> Post(s) • Page <?php echo $pageNum ?> of <?php echo $maxPage; ?></span></div> <!-- END BREADCRUMS --> <!-- START POSTS --> <?php if ($totalRows_grabposts >= 1) { ?> <span class="posts_holder"> <?php $row = 1; do { if($row == 1) { ?> <!-- START POST --> <span class="post"> <span class="post_content"> <span class="post_title"><?php echo $row_grabposts['Title']; ?> <?php if(((isset($_SESSION['CDA_Username'])) && ($_SESSION['CDA_Username'] == $row_grabposts['Owner'])) || ($_SESSION['CDA_Usergroup'] >= 2)) { ?> <span class="posteditbuttons"><a href="post.php?type=post&option=edit&p=<?php echo $row_grabposts['ID'];?>&t=<?php echo $_GET['t'];?>"> Edit</a></span> <?php } ?> </span> <span class="post_info">by <?php echo displayusername($row_grabposts['Owner']); ?> on <?php echo date("D jS M , h:i:s a",$row_grabposts['Date']); ?></span> <span class="post_message"> <?php output_post($row_grabposts['Post']); ?> </span> <span class="post_signature"> <?php getusersignature($row_grabposts['Owner']); ?> </span> </span> <span class="user_info"> <span class="user_avatar"><img src="../uploads/avatars/<?php getuserdetail($row_grabposts['Owner'], "Avatar"); ?>" width="115px" height="115px" alt="<?php getuserdetail($row_grabposts['Owner'], "Username"); ?>" /></span> <span class="user_name"><?php displayusername($row_grabposts['Owner']); ?></span> <span class="user_rank"><?php getuserdetail($row_grabposts['Owner'], "Rank"); ?></span> <span class="user_stat">Posts: <span><?php getuserdetail($row_grabposts['Owner'], "Posts"); ?></span></span> <span class="user_stat">Joined: <span><?php getuserdetail($row_grabposts['Owner'], "MemberSince"); ?></span></span> <span class="user_stat">Location: <span><?php getuserdetail($row_grabposts['Owner'], "Location"); ?></span></span> <span class="top"><a href="#top">Top</a></span> </span> </span> <!-- END POST --> <?php $row ++; } else if ($row == 2) { ?> <!-- START POST --> <span class="post post2"> <span class="post_content"> <span class="post_title"><?php echo $row_grabposts['Title']; ?> <?php if(((isset($_SESSION['CDA_Username'])) && ($_SESSION['CDA_Username'] == $row_grabposts['Owner'])) || ($_SESSION['CDA_Usergroup'] >= 2)) { ?> <span class="posteditbuttons"><a href="post.php?type=post&option=edit&p=<?php echo $row_grabposts['ID'];?>&t=<?php echo $_GET['t'];?>"> Edit</a></span> <?php } ?> </span> <span class="post_info">by <?php echo displayusername($row_grabposts['Owner']); ?> on <?php echo date("D jS M , h:i:s a", $row_grabposts['Date']); ?></span> <span class="post_message"> <?php output_post($row_grabposts['Post']); ?> </span> <span class="post_signature"> <?php getusersignature($row_grabposts['Owner']); ?> </span> </span> <span class="user_info user2"> <span class="user_avatar"><img src="../uploads/avatars/<?php getuserdetail($row_grabposts['Owner'], "Avatar"); ?>" width="115px" height="115px" alt="<?php getuserdetail($row_grabposts['Owner'], "Username"); ?>" /></span> <span class="user_name"><?php displayusername($row_grabposts['Owner']); ?></span> <span class="user_rank"><?php getuserdetail($row_grabposts['Owner'], "Rank"); ?></span> <span class="user_stat">Posts: <span><?php getuserdetail($row_grabposts['Owner'], "Posts"); ?></span></span> <span class="user_stat">Joined: <span><?php getuserdetail($row_grabposts['Owner'], "MemberSince"); ?></span></span> <span class="user_stat">Location: <span><?php getuserdetail($row_grabposts['Owner'], "Location"); ?></span></span> <span class="top"><a href="#top">Top</a></span> </span> </span> <!-- END POST --> <?php $row --; } } while ($row_grabposts = mysql_fetch_assoc($grabposts)); ?> </span> <?php } ?> <!-- END POSTS --> <div class="forum_navbar"><span><?php echo $first . $prev . $next . $last; ?></span></div> <div class="forum_bottombar"> <?php if($topic_locked != "yes") { ?> <span><input type="button" value="Post Reply" class="button" onclick="parent.location='post.php?type=post&f=<?php echo $_GET['f']; ?>&t=<?php echo $_GET['t']; ?>'" /></span> <?php } else { ?> <span><input type="button" value="Topic Locked" class="button" disabled="disabled"/></span> <?php } ?> <span class="right"><?php echo $rows_totalposts; ?> Post(s) • Page <?php echo $pageNum; ?> of <?php echo $maxPage; ?></span></div> <?php include("bottominfo.php"); ?> </div> </div> </div> <?php include("footer.php"); ?> <?php increasetopicviews($_GET['t']) ?> Quote Link to comment https://forums.phpfreaks.com/topic/173677-solved-creating-forums-topic-readunread/#findComment-915569 Share on other sites More sharing options...
Zane Posted September 9, 2009 Share Posted September 9, 2009 and you want to put the read/unread icon/emblem/text in between which two user-defined functions? note the user-defined part.....because...uh...I have no clue what's going on there. short of the fancy insinuating naming Quote Link to comment https://forums.phpfreaks.com/topic/173677-solved-creating-forums-topic-readunread/#findComment-915587 Share on other sites More sharing options...
Nixeon Posted September 9, 2009 Author Share Posted September 9, 2009 erm ... basically i want to make a function that will display the badge for example <?php // display topic badge function displaytopicbadge($topic_id) { // ... } ?> at the moment the function can tell whether the topic is locked but that it ... i want it to be able to tell if the user has read the topic since the last post was posted. at the moment my function looks like this: <?php //display topic badge function displaytopicbadge($topic_id) { // include database include("../functions/db_functions.php"); mysql_select_db($database_main_connection, $main_connection); // is topic locked? // Select locked status from the database $istopiclocked = mysql_query("SELECT Locked From forums_topics WHERE ID = $topic_id", $main_connection) or die(mysql_error()); $row_istopiclocked = mysql_fetch_assoc($istopiclocked); // if topic is locked display the locked badge if($row_istopiclocked['Locked'] == "yes") { echo '<img src="images/topiclocked.gif" alt="topic_locked" />'; } // is topic read? // code to find if topic is read here .... } ?> hope that makes more sense Quote Link to comment https://forums.phpfreaks.com/topic/173677-solved-creating-forums-topic-readunread/#findComment-915595 Share on other sites More sharing options...
Zane Posted September 9, 2009 Share Posted September 9, 2009 post your forum_topics schema do SHOW forum_topics in phpmyadmin or something Quote Link to comment https://forums.phpfreaks.com/topic/173677-solved-creating-forums-topic-readunread/#findComment-915599 Share on other sites More sharing options...
Nixeon Posted September 9, 2009 Author Share Posted September 9, 2009 Partial Texts Full Texts Relational key Relational display field Show binary contents Show BLOB contentsHide Browser transformation Field Type Null Key Default Extra ID int(255) NO PRI NULL auto_increment Title varchar(255) NO NULL Owner varchar(255) NO NULL DatePosted varchar(255) NO NULL Locked varchar(3) NO no ForumID int(255) NO NULL Views int(255) NO 0 lastpost_id int(255) NO NULL lastpost_user varchar(255) NO NULL lastpost_date varchar(255) NO NULL type varchar(255) NO normal That what you meant? Quote Link to comment https://forums.phpfreaks.com/topic/173677-solved-creating-forums-topic-readunread/#findComment-915611 Share on other sites More sharing options...
Zane Posted September 9, 2009 Share Posted September 9, 2009 I'll have to get back to you on this one...I'm stumped on the coding part, but I got the idea down. Yeah, back to this...you'd have one table for your basic activities for things view, edit, delete, etc, etc, on and on with permission and more elaborate stuff and then you'd have the actions table that links to it...or it links to that.. so when user 4896 views post 458345 at 3:30PM yada yada.... it is logged so in the function you query SELECT a.datetime, b.lastpost_date FROM activity a, actions INNER JOIN forums_topics b ON a.post = b.postID WHERE a.post = 458345 AND a.actionID = whatever"view"is no guarentees at all on this code...it's all ficticious really... Now at this point you have both the time the user last viewed this topic AND the last time ANYONE posted to this thread. Then you'll do the greater than or less than idea you had in mind at the beginning and the rest is pretty logical. Well..it seems that way...but when you begin to code it...you'll get the parse errors.. Quote Link to comment https://forums.phpfreaks.com/topic/173677-solved-creating-forums-topic-readunread/#findComment-915620 Share on other sites More sharing options...
Nixeon Posted September 9, 2009 Author Share Posted September 9, 2009 EDIT: HAHA just read your re-edited post i get what you mean now, don't think the table would get too big doing it your way... basically I need to keep in the table the topicID and last viewed not the latest postID. :-\ I think I get what you mean So I need a table that has columns like ID | UserID | PostViewed | Date | then when a user opens viewtopic.php run a script that inputs into the database AUTO INCREMENT -> ID $current_user -> UserID $latesttopicpostID -> PostViewed time() -> Date Then when displaying the badge I need to make it look what the latest post for the topic is ... grab it's id and then check if it's been viewed by the user by looking in the table. so something that does : Is post in the table? --- no, then unread --- yes, then is the username along side it --- no, then unread --- yes, then read Wont this table get MASSIVE though? Quote Link to comment https://forums.phpfreaks.com/topic/173677-solved-creating-forums-topic-readunread/#findComment-915638 Share on other sites More sharing options...
Zane Posted September 9, 2009 Share Posted September 9, 2009 Yeah you sorta got the idea a post logging table..... The only difference in between what you're thinking and I'm thinking is I'm saying you need an everything log table. Every single action of every single user of every single second. If they click a topic to view it...then by god...update the activity log..it's not like the data isn't there to update it with....hell, put their IP and browser type in there too just for fun...maybe even their...operating system name and all other kinds of information that you don't care about. Then as you are printing out your posts...in your "post printing loop" as we'll call it....or function then we have to actually check this table to see if the post is there for this user ..... on viewing charges.. which you pointed out. if it is there...get the time in which it happened and the time the last post was made in that particular topic and compare the two. The winner gets a badge either way. EDIT: Wont this table get MASSIVE though? This forum has pretty much the same concept I'm sure and it has over 85K users....how many users do you plan on having? Quote Link to comment https://forums.phpfreaks.com/topic/173677-solved-creating-forums-topic-readunread/#findComment-915645 Share on other sites More sharing options...
Nixeon Posted September 9, 2009 Author Share Posted September 9, 2009 Lol hopefully not that many people lmao. I understand fully what you mean now... many thanks for the help your a star. Quote Link to comment https://forums.phpfreaks.com/topic/173677-solved-creating-forums-topic-readunread/#findComment-915654 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.