Code: Select all
// top five topics
if (($user_topics = $cache->get('_top_five_topics')) === false)
{
$user_topics = array();
$sql = 'SELECT u.user_id AS u_id, u.username AS username, u.user_colour AS u_colour, COUNT(t.topic_id) AS count
FROM ' . TOPICS_TABLE. ' t, ' . USERS_TABLE . ' u
WHERE t.topic_approved = 1
AND t.topic_poster = u.user_id ' . $hide . '
GROUP BY u.user_id, u.username, u.user_colour
ORDER BY count DESC';
$result = $db->sql_query_limit($sql, 7);
while ($row = $db->sql_fetchrow($result))
{
$user_topics[$row['user_id']] = array(
'user_id' => $row['user_id'],
'username' => $row['username'],
'user_colour' => $row['user_colour'],
'user_regdate' => $row['user_regdate'],
'U_USER' => get_username_string('full', $current_user['u_id'], $current_user['username'], $current_user['u_colour']),
'COUNT' => $current_user['count'],
);
}
$db->sql_freeresult($result);
// cache this data for ever, cache is purged when adding or deleting users
$cache->put('_top_five_topics', $user_topics);
}
foreach ($user_topics as $row)
{
$username_string = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
$template->assign_block_vars('top_five_topics',array(
'USERNAME_FULL' => $username_string,
'U_USER' => get_username_string('full', $row['u_id'], $row['username'], $row['u_colour']),
'COUNT' => $row['count'])
);
}