protected static function recalculate_post($forum_id) { // update last post $result = dbquery("SELECT thread_lastpost, thread_lastuser FROM " . DB_FORUM_THREADS . " WHERE forum_id='" . $forum_id . "' ORDER BY thread_lastpost DESC LIMIT 0,1"); // get last thread_lastpost. if (dbrows($result)) { $data = dbarray($result); dbquery("UPDATE " . DB_FORUMS . " SET forum_lastpost='" . $data['thread_lastpost'] . "', forum_lastuser='" . $data['thread_lastuser'] . "' WHERE forum_id='" . $forum_id . "'"); } else { dbquery("UPDATE " . DB_FORUMS . " SET forum_lastpost='0', forum_lastuser='0' WHERE forum_id='" . $forum_id . "'"); } // update postcount on each threads - this is the remaining. $result = dbquery("SELECT COUNT(post_id) AS postcount, thread_id FROM " . DB_FORUM_POSTS . " WHERE forum_id='" . $forum_id . "' GROUP BY thread_id"); if (dbrows($result)) { while ($data = dbarray($result)) { dbquery("UPDATE " . DB_FORUM_THREADS . " SET thread_postcount='" . $data['postcount'] . "' WHERE thread_id='" . $data['thread_id'] . "'"); } } // calculate and update total combined postcount on all threads to forum $result = dbquery("SELECT SUM(thread_postcount) AS postcount, forum_id FROM " . DB_FORUM_THREADS . "\n\t\tWHERE forum_id='" . $forum_id . "' GROUP BY forum_id"); if (dbrows($result)) { while ($data = dbarray($result)) { dbquery("UPDATE " . DB_FORUMS . " SET forum_postcount='" . $data['postcount'] . "' WHERE forum_id='" . $data['forum_id'] . "'"); } } // calculate and update total threads to forum $result = dbquery("SELECT COUNT(thread_id) AS threadcount, forum_id FROM " . DB_FORUM_THREADS . " WHERE forum_id='" . $forum_id . "' GROUP BY forum_id"); if (dbrows($result)) { while ($data = dbarray($result)) { dbquery("UPDATE " . DB_FORUMS . " SET forum_threadcount='" . $data['threadcount'] . "' WHERE forum_id='" . $data['forum_id'] . "'"); } } }