@
fangzhzh 再次感谢。
新手学语言,还是测试一次最能吸收。
昨天测试过了,DESC LIMIT 10 我知道什么意思,我复制代码提问的时候,忘记去掉了,谢谢你的提醒。
我因为要或者不同类型的数据,导致一个页面查询很多次,不知道有什么好的方法让查询次数少一点呢。
以下是我在对discuz作修改的时候加入的代码,请赐教。
我的想法:
1、获取新主题,但是过滤上级论坛分类 ( fup not in (6) ),过滤匿名发表的主题(author !='')。
2、获取最近回复的主题,同样论坛分类 6 ( fup not in (6) ),过滤匿名发表的主题(author !='')。
3、由于上级论坛分类6是一个原创专区,所以我单独获取这个分区的最新帖子。
//newthread start
$colorarray = array('', 'red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple', 'gray');
$hack_cut_str = 50;
$hack_cut_strauthor = 9;
$new_post_threadlist = array();
$nthread = array();
$query = $db->query("SELECT t.*,
f.name FROM {$tablepre}threads t, {$tablepre}forums f WHERE f.fup not in (6) AND t.fid<>'$fid' AND f.fid=t.fid AND f.fid not in (0) AND t.displayorder not in (-1,-2) AND author !='' ORDER BY t.dateline DESC LIMIT 0, 20");
while($nthread = $db->fetch_array($query)) {
$nthread['forumname'] = strip_tags($nthread['name']);
$nthread['view_subject'] = cutstr($nthread['subject'],$hack_cut_str);
$nthread['view_author'] = cutstr($nthread['author'],$hack_cut_strauthor);
$nthread['date'] = dgmdate("$dateformat $timeformat", $nthread['dateline'] + $timeoffset * 3600);
$nthread['lastreplytime']= dgmdate("$dateformat $timeformat", $nthread[lastpost] + ($timeoffset * 3600));
if($nthread['highlight']) {
$string = sprintf('%02d', $nthread['highlight']);
$stylestr = sprintf('%03b', $string[0]);
$nthread['highlight'] = 'style="';
$nthread['highlight'] .= $stylestr[0] ? 'font-weight: bold;' : '';
$nthread['highlight'] .= $stylestr[1] ? 'font-style: italic;' : '';
$nthread['highlight'] .= $stylestr[2] ? 'text-decoration: underline;' : '';
$nthread['highlight'] .= $string[1] ? 'color: '.$colorarray[$string[1]] : '';
$nthread['highlight'] .= '"';
} else {
$nthread['highlight'] = '';
}
$new_post_threadlist[] = $nthread;
}
//newthread end
//newreply start
$new_reply_threadlist = array();
$rthread = array();
$query = $db->query("SELECT t.*,
f.name FROM {$tablepre}threads t, {$tablepre}forums f WHERE f.fup not in (6) AND t.fid<>'$fid' AND f.fid=t.fid AND t.closed NOT LIKE 'moved|%' AND t.replies !=0 AND f.fid not in (0) AND t.displayorder not in (-1,-2) AND author !='' ORDER BY t.lastpost DESC LIMIT 0, 20");
while($rthread = $db->fetch_array($query)) {
$rthread['forumname'] = ereg_replace('<[^>]*>','',$rthread['name']);
$rthread['view_subject'] = cutstr($rthread['subject'],$hack_cut_str);
$rthread['view_lastposter'] = cutstr($rthread['lastposter'],$hack_cut_strauthor);
$rthread['date']= dgmdate("$dateformat $timeformat", $rthread['dateline'] + $timeoffset * 3600);
$rthread['lastreplytime']= dgmdate("$dateformat $timeformat", $rthread[lastpost] + ($timeoffset * 3600));
if($rthread['highlight']) {
$string = sprintf('%02d', $rthread['highlight']);
$stylestr = sprintf('%03b', $string[0]);
$rthread['highlight'] = 'style="';
$rthread['highlight'] .= $stylestr[0] ? 'font-weight: bold;' : '';
$rthread['highlight'] .= $stylestr[1] ? 'font-style: italic;' : '';
$rthread['highlight'] .= $stylestr[2] ? 'text-decoration: underline;' : '';
$rthread['highlight'] .= $string[1] ? 'color: '.$colorarray[$string[1]] : '';
$rthread['highlight'] .= '"';
} else {
$rthread['highlight'] = '';
}
$new_reply_threadlist[] = $rthread;
}
//newreply end
//myspace start
$my_post_threadlist = array();
$mythread = array();
$query = $db->query("SELECT t.*,
f.name FROM {$tablepre}threads t, {$tablepre}forums f WHERE f.fup in (6) AND t.fid<>'$fid' AND f.fid=t.fid AND f.fid not in (0) AND t.displayorder not in (-1,-2) AND author !='' ORDER BY t.dateline DESC LIMIT 0, 20");
while($mythread = $db->fetch_array($query)) {
$mythread['forumname'] = strip_tags($mythread['name']);
$mythread['view_subject'] = cutstr($mythread['subject'],$hack_cut_str);
$mythread['view_author'] = cutstr($mythread['author'],$hack_cut_strauthor);
$mythread['date'] = dgmdate("$dateformat $timeformat", $mythread['dateline'] + $timeoffset * 3600);
$mythread['lastreplytime']= dgmdate("$dateformat $timeformat", $mythread[lastpost] + ($timeoffset * 3600));
$my_post_threadlist[] = $mythread;
}
//myspace end