How to determine new posts for a thread?
Posted: Sun Mar 12, 2006 1:15 am
Hello,
As you can tell from my previous post, I have not been actively coding PHP in quite some time. However, I'm getting back into it.
When I stopped coding I was working on a forum. Well, I have revisited that project.
I am working on a site and have modified the forum software to work with this current infrastructure, which was fairly similar to the one it was originally written for.
One of the main issues I've had --and had even when I was writing it originally-- was how to determine new posts.
I considered many different options, but decided I'd similar compare the time of the last post and such.
I'm storing all times in the database with time() (and I know there is some controversy about that). When the page is loaded, the functions.php scripted is loaded and this is code that is evaluated:
Now this DOES work, but when the user logs back in after some time of inactivity, it is (obviously) resetting their time. So whenever you view the forums after logging back in after a couple minutes of inactivity, there are no new threads because the above script is updating the user's database row.
So I need to figure out a way to determine a certain amount of inactivity and not upload the script right away if that condition is met. I'm not great when it comes to math and equations, so this has been rather difficult for me, which is compounded by the fact that I've been away from PHP for such a long time.
I've considered using cookies to track the topics and I've also considered having a database table that simple keeps track of it all and deletes it when a new post is added, but there'd be an awful lot data almost needlessly stored in the database.
I've also considered just checking the forumlastvisit variable and multiplying it by like ten minutes. If the user has not logged in for at least that amount, it doesn't update the time until after they have been given ample time, but then I can't think of how to get out of that condition!
Does anyone have any ideas on how I can do this, or of other ways I can efficiently keep track of thread views?
I don't need it to be insanely accurate, but I've tried several ideas to not reset the time and I've even considered just keeping it how it is now. But I'd even be a little annoyed that everytime I came back to the forum and knew there were posts but the forum was specifically telling me that there were not.
I'm sure there is a simple solution that is simply escaping me, but I've been struggling with this.
Thanks.
P.S. I believe this is the aspect of the script that frustrated me so much that I quit coding! lol.
As you can tell from my previous post, I have not been actively coding PHP in quite some time. However, I'm getting back into it.
When I stopped coding I was working on a forum. Well, I have revisited that project.
I am working on a site and have modified the forum software to work with this current infrastructure, which was fairly similar to the one it was originally written for.
One of the main issues I've had --and had even when I was writing it originally-- was how to determine new posts.
I considered many different options, but decided I'd similar compare the time of the last post and such.
I'm storing all times in the database with time() (and I know there is some controversy about that). When the page is loaded, the functions.php scripted is loaded and this is code that is evaluated:
Code: Select all
$_lastvisit_min = 4;
$forum_lastvisit_time = time() - (60 * $_lastvisit_min);
....
if ($issession) {
global $session;
$update_session_forum = $DB->query("UPDATE sessions SET forumlastvisit='".time()."' WHERE sessionhash='".addslashes($session['hash'])."' AND userid='".addslashes($user['userid'])."' LIMIT 1");
if ($user['forumlastvisit'] < $forum_lastvisit_time) {
$DB->query("UPDATE login SET forumlastvisit='".time()."' WHERE userid='".$user['userid']."' LIMIT 1");
}
}So I need to figure out a way to determine a certain amount of inactivity and not upload the script right away if that condition is met. I'm not great when it comes to math and equations, so this has been rather difficult for me, which is compounded by the fact that I've been away from PHP for such a long time.
I've considered using cookies to track the topics and I've also considered having a database table that simple keeps track of it all and deletes it when a new post is added, but there'd be an awful lot data almost needlessly stored in the database.
I've also considered just checking the forumlastvisit variable and multiplying it by like ten minutes. If the user has not logged in for at least that amount, it doesn't update the time until after they have been given ample time, but then I can't think of how to get out of that condition!
Does anyone have any ideas on how I can do this, or of other ways I can efficiently keep track of thread views?
I don't need it to be insanely accurate, but I've tried several ideas to not reset the time and I've even considered just keeping it how it is now. But I'd even be a little annoyed that everytime I came back to the forum and knew there were posts but the forum was specifically telling me that there were not.
I'm sure there is a simple solution that is simply escaping me, but I've been struggling with this.
Thanks.
P.S. I believe this is the aspect of the script that frustrated me so much that I quit coding! lol.