TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 348
  • Total: 348

[Block] Top Posters with avatar

Started by IchBin, June 22, 2009, 08:30:58 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

shane is my name

oh ok Thanks IchBin, I appreciate the explanation.

ZarPrime

Shane,

If you're really interested in the changes in SMF 2.0, take a seat and have a read of this topic --> http://docs.simplemachines.org/index.php?topic=1433

This will give you a at least a basic understanding of some of the changes.

ZarPrime

IchBin

Code should be updated in that topic now.

shane is my name

Thanks IchBin,  it's a great code. Im going to try it again now.

and Thanks for the link ZarPrime.  yeah i am interested. Im always trying to learn more..  Im always buying books etc trying to do this and that.. and I thought I was kind of good, until I started using smf and TP,  and now im lost at every turn. lol,  but one of these days,,, 

shuban

It's very strange, but one of my posters who is the top 10 isn't being shown in this list. What do you think could be the reason why this one user isn't being shown?

Freddy


shuban

Hi everyone,

I really like this snippet's layout:

http://www.tinyportal.net/index.php?topic=31670.0

Although I want it to display the top posters in past 7 days (i.e. in the last week).

Could someone please modify it for me?

saks

Very good ! Now it work properly!  O0

shuban

Quote from: shuban on October 02, 2011, 07:40:04 PM
Hi everyone,

I really like this snippet's layout:

http://www.tinyportal.net/index.php?topic=31670.0

Although I want it to display the top posters in past 7 days (i.e. in the last week).

Could someone please modify it for me?

Okay, I've got it down to this, but I do not know how to include an avatar! :(

global $db_prefix, $scripturl, $context, $settings;

// Top 10 Posters so far this week  (starts sunday)
$starttime = mktime(0, 0, 0, date("n"), date("j"), date("Y")) - (date("N")*3600*24);
// Offset based on forum time
$starttime = forum_time(false, $starttime);

$request = db_query("
SELECT me.ID_MEMBER, me.realName, COUNT(*) as count_posts
FROM {$db_prefix}messages AS m
LEFT JOIN {$db_prefix}members AS me ON (me.ID_MEMBER = m.ID_MEMBER)
WHERE m.posterTime > " . $starttime . "
AND m.ID_MEMBER != 0
GROUP BY me.ID_MEMBER
ORDER BY count_posts DESC
LIMIT 7", __FILE__, __LINE__);

$context['top_posters_week'] = array();
$max_num_posts = 1;
while ($row_members = mysql_fetch_assoc($request))
{
$context['top_posters_week'][] = array(
'name' => $row_members['realName'],
'id' => $row_members['ID_MEMBER'],
'num_posts' => $row_members['count_posts'],
'href' => $scripturl . '?action=profile;u=' . $row_members['ID_MEMBER'],
'avatar' => array(
    'image' => empty($row['avatar']) ? ($row['ID_ATTACH'] > 0 ? 'src="' . (empty($row['attachmentType']) ? $scripturl . '?action=dlattach;attach=' . $row['ID_ATTACH'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $row['filename']) . '" alt="" border="0" width="30px" height="30px" title="'.$row['realName'].'" />' : '') : (stristr($row['avatar'], 'http://') ? 'src="' . $row['avatar'] . '" alt="" border="0" width="30px" height="30px" title="'.$row['realName'].'" />' : 'src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($row['avatar']) . '" alt="" border="0" width="30px" height="30px" title="'.$row['realName'].'" />'),
    ),
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['ID_MEMBER'] . '">' . $row_members['realName'] . '</a>'
);

if ($max_num_posts < $row_members['count_posts'])
$max_num_posts = $row_members['count_posts'];
}
mysql_free_result($request);

foreach ($context['top_posters_week'] as $i => $j)
$context['top_posters_week'][$i]['post_percent'] = round(($j['num_posts'] * 100) / $max_num_posts);

// Tidy up
unset($max_num_posts, $row_members, $j, $i);

echo '
<table cellpadding="0" cellspacing="4">';

foreach ($context['top_posters_week'] as $poster)
echo '
<tr>

<td style="overflow: hidden;"><a href="'.$poster['href'].'"><img '.$poster['avatar']['image'].'</a></td>

<td style="overflow: hidden;"><h5 style="margin: 4px;">', $poster['link'], '</h5><h5 style="margin: 4px;">', $poster['num_posts'], '</h5></td>
</tr>';
echo '
</table>';


Please help! I think it's here:

$request = db_query("
      SELECT me.ID_MEMBER, me.realName, COUNT(*) as count_posts
      FROM {$db_prefix}messages AS m
         LEFT JOIN {$db_prefix}members AS me ON (me.ID_MEMBER = m.ID_MEMBER)


That I have to include something about avatars in order for this part (below), to work!

<td style="overflow: hidden;"><a href="'.$poster['href'].'"><img '.$poster['avatar']['image'].'</a></td>

This website is proudly hosted on Crocweb Cloud Website Hosting.