emlog评论:读者排行榜
[ 2015/01/08, Emlog , 2886阅, 0评 ]
思路:分别统计每个邮箱出现的次数,然后按照次数从高到低的顺序显示出符合where条件的结果。

emlog评论排行榜.jpg

1.查询所有评论

<?php
function top_commenter($num){
	$url .=BLOG_URL.'';
	$db = MySql :: getInstance();
	$sql = "SELECT count(*) AS comment_nums,poster,mail,url FROM ".DB_PREFIX."comment where date >0 and poster!='' and url!='".$url."' and hide='n' group by mail order by comment_nums DESC limit ".$num."";
	$result = $db->query($sql);
	while($row = $db->fetch_array($result)){
		echo "<li><a href='".$row['url']."' title='".$row['poster'].":共评论".$row['comment_nums']."次' target=\"_blank\"><img src='".myGravatar($row['mail'])."'/></a></li>";
	}
}
?>
<?php top_commenter(5);?>

2.查询30天内的评论

<?php
function hot_commenter($num){
	$url .=BLOG_URL.'';
	$time = time();
	$db = MySql :: getInstance();
	$sql = "SELECT count(*) AS comment_nums,poster,mail,url FROM ".DB_PREFIX."comment where date > $time - 30*24*60*60 and poster!='' and url!='".$url."' and hide='n' group by mail order by comment_nums DESC limit ".$num."";
	$result = $db->query($sql);
	while($row = $db->fetch_array($result)){
		echo "<li><a href='".$row['url']."' title='".$row['poster'].":共评论".$row['comment_nums']."次' target=\"_blank\"><img src='".myGravatar($row['mail'])."'/></a></li>";
	}
}
?>
<?php hot_commenter(5);?>

有朋自远方来...评论一下呗O(∩_∩)O