首页| 版块| 我的| 发帖| 消息
主题:2016年1月15日:修正电脑版论坛统计数据主题数和帖子数误差(部分与拆分操作有关)
zhangjingyu 
44楼提到的完整代码贴下。
require/updateforum.php
function updateforum($fid,$lastinfo='') {//TODO 慢查询
global $db,$db_fcachenum,$todayTopicNum;
$fm = $db->get_one("SELECT fup,type,password,allowvisit,f_type FROM pw_forums WHERE fid=".S::sqlEscape($fid));
if ($fm['type'] != 'category') {
$subtopics = $subrepliess = 0;
$query = $db->query("SELECT fid FROM pw_forums WHERE fup=".S::sqlEscape($fid));
while ($subinfo = $db->fetch_array($query)) {
@extract($db->get_one("SELECT COUNT(*) AS subtopic,SUM( replies ) AS subreplies FROM pw_threads WHERE fid=".S::sqlEscape($subinfo['fid'])." AND ifcheck='1'"));
$subtopics += $subtopic;
$subrepliess += $subreplies;
$query2 = $db->query("SELECT fid FROM pw_forums WHERE fup=".S::sqlEscape($subinfo['fid']));
while ($subinfo2 = $db->fetch_array($query2)) {
@extract($db->get_one("SELECT COUNT(*) AS subtopic,SUM( replies ) AS subreplies FROM pw_threads WHERE fid=".S::sqlEscape($subinfo2['fid'])." AND ifcheck='1'"));
$subtopics += $subtopic;
$subrepliess += $subreplies;
}
}
$rs = $db->get_one("SELECT COUNT(*) AS topic,SUM( replies ) AS replies FROM pw_threads WHERE fid=".S::sqlEscape($fid)."AND ifcheck='1' AND toppedget_one("SELECT tid,author,postdate,lastpost,lastposter,subject FROM pw_threads WHERE fid=".S::sqlEscape($fid)." AND specialsort=0 AND ifcheck=1 AND lastpost>0 ORDER BY lastpost DESC LIMIT 1");
if ($lt['postdate'] == $lt['lastpost']) {
$subject = addslashes(substrs($lt['subject'],26));
} else {
$subject = 'Re:'.addslashes(substrs($lt['subject'],26));
}
$author= addslashes($lt['lastposter']);
$lastinfo = $lt['tid'] ? $subject."\t".$author."\t".$lt['lastpost']."\t"."read.php?tid=$lt[tid]&page=e#a" : '' ;
}
/**
$db->update("UPDATE pw_forumdata"
. " SET ".S::sqlSingle(array(
'topic'=> $topic,
'article'=> $article,
'subtopic'=> $subtopics,
'lastpost'=> $lastinfo
))
. " WHERE fid=".S::sqlEscape($fid));
**/
pwQuery::update('pw_forumdata', 'fid=:fid', array($fid), array(
'topic'=> $topic,
'article'=> $article,
'subtopic'=> $subtopics,
'lastpost'=> $lastinfo
));
$todayTopicNum && $db->update("UPDATE pw_forumdata SET tpost = tpost+$todayTopicNum WHERE fid=" . S::sqlEscape($fid));
if ($fm['password'] != '' || $fm['allowvisit'] != '' || $fm['f_type'] == 'hidden') {
$lastinfo = '';
}
delfcache($fid,$db_fcachenum);
if ($fm['type'] == 'sub' || $fm['type'] == 'sub2') {
updateforum($fm['fup'],$lastinfo);
}
}
}
zhangjingyu回帖于2020-09-13 22:06[查看电脑版]
下一页 (1/2)
下一楼»:假设版块a下面有b和c,也就是a是b和c的父版块,b和c是a的子版块。现在的情况是,在父版块a的版块 ..
«上一楼:不要睡得太晚了,注意身体。晚安!

查看全部回帖(203)
«返回主帖