MyBB Community Forums

Full Version: Today's most popular forum
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
At the moment there is today's top poster and most popular forum. I was thinking that today's most popular forum could be added.
I have acchived this but it uses 3 queries.
It gets the right forum, right number of posts and threads.

See more information in this commit: [a1af060fbb]

I will be experimenting how to lessen the number of queries.

This is the code that I have added to stats.php
// Today's top forum
$timesearch = TIME_NOW - 86400;
if(!empty($fidnot))
{
	$fidnot .= " AND";
}
$query = $db->query("
	SELECT p.fid, f.fid, f.name, f.posts, f.threads, COUNT(*) AS poststoday
	FROM ".TABLE_PREFIX."posts p
	LEFT JOIN ".TABLE_PREFIX."forums f ON (p.fid=f.fid)
	WHERE p.dateline > {$timesearch}
	GROUP BY p.fid ORDER BY poststoday DESC
	LIMIT 1
");
$forum = $db->fetch_array($query);
if(!$forum['posts'])
{
	$todaystopforum = $lang->none;
	$todaystopforumposts = $lang->no;
	$todaystopforumthreads = $lang->no;
}
else
{
	// Find the threads created today
	$query = $db->query("
		SELECT COUNT(*) AS threadstoday
		FROM ".TABLE_PREFIX."threads
		WHERE dateline > {$timesearch}
		AND fid = {$forum['fid']}
	");
	$threads = $db->fetch_array($query);
	// Find posts created today
	$query = $db->query("
		SELECT COUNT(*) AS poststoday
		FROM ".TABLE_PREFIX."posts
		WHERE dateline > {$timesearch}
		AND fid = {$forum['fid']}
	");
	$posts = $db->fetch_array($query);
	// Set up the forum link
	$forum['link'] = get_forum_link($forum['fid']);
	
	$todaystopforum = "<a href=\"{$forum['link']}\">{$forum['name']}</a>";
	$todaystopforumposts = $posts['poststoday'];
	$todaystopforumthreads = $threads['threadstoday'];
}
$lang->todays_popular_forum = $lang->sprintf($lang->todays_popular_forum, $todaystopforum, my_number_format($todaystopforumposts), my_number_format($todaystopforumthreads));
and stats.lang.php
$l['todays_popular_forum'] = "Today's most popular forum: <b>{1}</b> (<b>{2}</b> posts, <b>{3}</b> threads)";
Today's most popular forum: Forum Games
Yesterday's most popular forum: Forum Games
Everyday's most popular forum: Forum Games