php+select为空,SELECT时候,如何处理某字段空值?

博客内容涉及对Discuz论坛代码的修改,旨在减少查询次数。作者试图通过三部分实现这一目标:1) 获取非特定分类的新主题,过滤匿名帖子;2) 获取有回复的帖子,同样进行分类过滤;3) 特别获取原创专区的最新帖子。代码中包含了SQL查询和数据处理,以提高页面加载效率。
摘要由CSDN通过智能技术生成

8

2012-12-10 12:17:52 +08:00

@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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值