Get popular topics, sort by replies

General discussion of development ideas and the approaches taken in the 3.x branch of phpBB. The current feature release of phpBB 3 is 3.3/Proteus.
Forum rules
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.3.x. If you need support for phpBB 3.3.x please visit the 3.3.x Support Forum on phpbb.com.

If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
Post Reply
archon
Registered User
Posts: 6
Joined: Wed Mar 05, 2014 4:16 pm

Get popular topics, sort by replies

Post by archon »

Hi.

I have a custom portal that was made for phpBB 3.0.x and I need to convert it to phpBB 3.1.

Code: Select all

$sql = 'SELECT topic_id, forum_id, topic_poster, topic_first_poster_colour, topic_title, topic_first_poster_name, topic_time FROM ' . TOPICS_TABLE . ' WHERE forum_id != 12 AND forum_id != 3 ORDER BY topic_replies DESC, topic_time DESC';
$result = $db->sql_query_limit($sql, $portal_config['topics']);

while ($row = $db->sql_fetchrow($result))
{
	$template->assign_block_vars('latest_hot_topics', array(
		'TOPIC_TITLE' => $row['topic_title'],
		'TOPIC_LINK' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']),
		'TOPIC_REPLIES' => $this->get_topic_replies($row['topic_id']),
		'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']),
	));
}

private function get_topic_replies($topic_id)
{
	global $db;
	$sql = 'SELECT COUNT(post_id) AS post_count FROM ' . POSTS_TABLE . ' WHERE ' . POSTS_TABLE . '.topic_id = ' . $topic_id . '';
		
	$result = $db->sql_query($sql);
	$post_count = (int)$db->sql_fetchfield('post_count');
	$db->sql_freeresult($result);
	
	return $post_count - 1;
}

User avatar
nickvergessen
Former Team Member
Posts: 733
Joined: Sun Oct 07, 2007 11:54 am
Location: Stuttgart, Germany
Contact:

Re: Get popular topics, sort by replies

Post by nickvergessen »

ORDER BY topic_posts_approved
Member of the Development-TeamNo Support via PM

archon
Registered User
Posts: 6
Joined: Wed Mar 05, 2014 4:16 pm

Re: Get popular topics, sort by replies

Post by archon »

Thanks, I already got an answer on IRC but forgot to update my post here.

Post Reply