1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Creating Custom Forum but can't get my mind around an issue

Discussion in 'PHP' started by Silver89, Jul 29, 2008.

  1. #1
    Hi,

    I'm coding a custom forum for one of my sites, however one part is really confusing me and I can't get my head around how to code it to get it to function correctly.

    Basically the base of the forum is done now and works with the current database however I'm now wondering how to create a function that shows if a user has read all the posts in a particular thread and if they have seen the newest thread.

    The only way I can think of is use a Mysql_query to insert their "last read post time" into a column. Then any posts after this time show up as unread/new post?

    -Dan
     
    Silver89, Jul 29, 2008 IP
  2. Pos1tron

    Pos1tron Peon

    Messages:
    95
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I believe the way this is done in some forums is to get the last time they were on the forum (users' row in the users table in the db perhaps), and any threads/posts posted after that, they haven't seen and so are displayed as new.

    The problems with that are that someone who didn't get a chance to look through everything on their last visit won't know what's new since their last visit. I'm pretty certain it's not done like that nowadays, it's done in a way perhaps like yours that solves the problem.

    I suppose one way would be to have a table that gets a new row in whenever a user visits a new thread, and updated when a user revisits a thread, saying the most recent time they accessed it, and then you calculate new posts via the previously mentioned method. If the row doesn't exist, the entire thread is new to the user.

    You could, to keep database size down, have it that if the last post in a thread is over 2 weeks old, then it is not shown as new to the user - every day/week, a script could be run via a cron job or something, that deletes rows in that database that refer to a thread that has not had a new post in 2 weeks or more. If run everyday, the max time threads could ever be displayed as new for would be just under 2 weeks 1 day, or if every week, just under 3 weeks.
     
    Pos1tron, Jul 31, 2008 IP
  3. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This appears to be IPB's setup:

    `topic_markers` (
      `marker_member_id` int(8) NOT NULL default '0',
      `marker_forum_id` int(10) NOT NULL default '0',
      `marker_last_update` int(10) NOT NULL default '0',
      `marker_unread` smallint(5) NOT NULL default '0',
      `marker_topics_read` text,
      `marker_last_cleared` int(10) NOT NULL default '0',
      UNIQUE KEY `marker_forum_id` (`marker_forum_id`,`marker_member_id`),
      KEY `marker_member_id` (`marker_member_id`)
    )
    Code (markup):
    Here is one exported row as an example to show what it stores in it:

    (5, 17, 1207274667, 241, 'a:85:{i:91;i:1183350460;i:99;i:1183394104;i:102;i:1183397409;i:115;i:1183408208;i:119;i:1183486899;i:125;i:1183411327;i:128;i:1183426390;i:129;i:1183486857;i:136;i:1183435484;i:146;i:1190077738;i:140;i:1183489800;i:150;i:1183489839;i:162;i:1183590816;i:163;i:1183602009;i:173;i:1183587797;i:181;i:1183670899;i:190;i:1183659898;i:83;i:1183689087;i:201;i:1183775606;i:206;i:1183860459;i:219;i:1184023192;i:224;i:1184026703;i:223;i:1184023163;i:225;i:1184105795;i:234;i:1184202282;i:237;i:1184100510;i:228;i:1184100512;i:233;i:1184100513;i:251;i:1184129520;i:258;i:1184179456;i:262;i:1184265990;i:278;i:1184266018;i:281;i:1184298786;i:305;i:1185818843;i:329;i:1184611315;i:333;i:1184607258;i:356;i:1184820449;i:372;i:1184879007;i:392;i:1184902731;i:395;i:1185409949;i:396;i:1184894939;i:403;i:1184955754;i:404;i:1184966802;i:411;i:1184972827;i:412;i:1184992492;i:417;i:1185044407;i:419;i:1185061283;i:420;i:1185132756;i:437;i:1185236783;i:440;i:1185236804;i:450;i:1185250477;i:465;i:1185475775;i:464;i:1185818902;i:475;i:1185475840;i:487;i:1185561950;i:488;i:1185562025;i:496;i:1185745688;i:500;i:1185818940;i:513;i:1185818884;i:517;i:1185818927;i:534;i:1186016234;i:558;i:1186088668;i:580;i:1186200914;i:587;i:1186249678;i:595;i:1186289304;i:600;i:1186358827;i:607;i:1186426417;i:605;i:1186426434;i:610;i:1186433153;i:615;i:1186439970;i:621;i:1186515567;i:689;i:1186879849;i:759;i:1187486934;i:792;i:1187550579;i:829;i:1187911673;i:874;i:1188257182;i:919;i:1188683621;i:996;i:1189295264;i:1116;i:1190512402;i:1179;i:1190942086;i:3050;i:1207190330;i:3051;i:1207190593;i:2931;i:1207190489;i:3069;i:1207274536;i:3083;i:1207274667;}', 1183346030)
    Code (markup):
    It seems to create a row for each different forum section for each member and such. The marker_topics_read column seems to store a serialized array containing all the topic IDs and I guess the timestamp that they last read said thread.

    Hope that helps.
     
    zerxer, Jul 31, 2008 IP
    Silver89 likes this.
  4. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #4
    It's taken me a good few hours to code, but I now have it so when a user posts a comment it inserts it into table. Everyone else who has posted in that thread will get a notification of a new post which goes when they read it.

    Do you ever finish coding complex things and just think how the hell did I manage that?
     
    Silver89, Jul 31, 2008 IP