我难住了。我想从“帖子”中获得平均“点击次数”,但丢弃通常很高的最高值,以至于当我想显示所有点击次数高于平均水平的帖子时,它会扭曲阈值。出于同样的原因,我也想丢弃最低值。我的代码是:
//get the sum of the clicks from all posts
$gettotalsum = mysql_query("SELECT sum(clicks) AS click_total FROM posts WHERE clicks > '0' ");
$clicksum = @mysql_fetch_array($gettotalsum);
//get the number of posts that have clicks
$postcount = mysql_query("SELECT postid FROM posts WHERE isactive = 'y' AND clicks > '0' ");
$clickcount = mysql_num_rows($postcount);
我怀疑上面的两个查询是我需要修改以过滤最高和最低点击值 - 但是如何?
这是我剩下的代码fwiw:
//multiply to get the average, then round it off
$average = $clicksum['clicks'] / $clickcount;
$average = round($average);
//display posts that are equal to or above average
$getposts = mysql_query("SELECT postid, posturl, posttitle, clicks FROM posts WHERE clicks >= $average order by clicks DESC");
while ($aboveaverageposts = @mysql_fetch_array($getposts)) {
//code to format output goes here
}
我确实怀疑所有这些代码都可以简化,但现在最重要的是我正在寻找过滤最高和最低值。
提前致谢。