Logical problem. Started forum from scratch, need advice on legends

Discussion in 'Programming' started by lee.marsh, Jul 20, 2009.

  1. #1
    Hey guys,

    Ok. I took on the monster task of coding my own forums for a site of mine! (Ouchies. But, in all honesty.. they're not overly complicated. It was much easier to implement a forum into the current user system than convert the user system into a forum)

    Even though i did the code in PHP.. it's not necessarily a php problem :)

    So, the forum is just about finished. Just one little problem holding me back...

    You know when you view a forum? And there's the forum legend at the bottom (a 'key'..). Well, let's say we have 2..

    • New Posts
    • No New Posts

    So.. i figured the easiest way to do it would be to have a column in the users field.. with $user->last_loggedin.. and a collumn in the forums field $forum['last_updated'].. meaning i could simply..

    
    <?
    if($user->last_loggedin > $forum['last_updated']){
         // show the "New posts!" icon
    } else {
         // show the "Nooo new posts!" icon
    }
    ?>
    
    PHP:
    Now, the problem arrises when the user is logged in.. everything is fine.. until someone else posts a new topic/post..

    That then means, that the $user->last_loggedin < $forum['last_updated'].. meaning that the forum doesn't show as being updated.. doh!

    I could reverse the arguments of the original php code (above).. so that...

    
    <?
    if($user->last_loggedin < $forum['last_updated']){
         // show the "New posts!" icon
    } else {
         // show the "Nooo new posts!" icon
    }
    ?>
    
    PHP:
    But then that will throw out my "New posts" when the user first logs in..

    It seems it's one or the other..

    And damn, that seems like a really complicated way of saying that.. but i thought in detail would be the best way. It's driving me crazy.

    Is there any way to get both? Like.. i know vbulletin and other forum software manages it, but i don't really fancy trolling through vast amounts of code like that.
     
    lee.marsh, Jul 20, 2009 IP
  2. jbrooksuk

    jbrooksuk Active Member

    Messages:
    127
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    81
    #2
    So you're saying if you are logged in nothing works, but when you're logged out it works fine?
     
    jbrooksuk, Jul 21, 2009 IP
  3. stOK

    stOK Active Member

    Messages:
    114
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    The problem I think is that when your user logs in you update his lastlogin time.
    You should store his last logout time I believe rather than his last login time.
    And all posts since the user logged out last time should be considered new during his current session.
    IMHO.
     
    stOK, Jul 22, 2009 IP