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

Recent

Welcome to TinyPortal. Please login or sign up.

March 29, 2024, 06:14:16 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,106
  • Total Topics: 21,213
  • Online today: 358
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online

Top posters

Started by JPDeni, September 20, 2006, 01:27:56 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JPDeni

This is a list of top posters within a specific time frame, such as for a posting contest. As it stands, it lists the 10 most prolific posters, with the number of posts and a link to the posters' profiles.

First, you need to find out the unix time for when you want it to start and end. You can compute it here, among many other places. Put those numbers into the $starttime and $endtime variables below.

The code does not count admins or global moderators and prints out the 10 most prolific posters within the time frame, with the number of posts in parentheses after the name. There isn't any error checking for the beginning when there won't be any posts, though. It also prints a link to the profile, which you can delete if you want.


global $db_prefix, $scripturl;

$starttime = 1152182762; // Change this to the time you want the contest to start
$endtime = 1152405444;  // Change this to the time you want the contest to end

$count= array();
$poster_number = array();
$query = db_query(
    "SELECT posterName, {$db_prefix}messages.ID_MEMBER, ID_GROUP
     FROM {$db_prefix}members
     JOIN {$db_prefix}messages
     ON {$db_prefix}members.ID_MEMBER = {$db_prefix}messages.ID_MEMBER
     WHERE ID_GROUP <> 1 AND ID_GROUP <> 2
     AND posterTime > $starttime
     AND posterTime < $endtime", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($query))
{
  if (!isset($count[$row['posterName']]))
    $count[$row['posterName']] = 0;
  ++$count[$row['posterName']];
    $poster_number[$row['posterName']] = $row['ID_MEMBER'];
}

arsort($count);
$list_number = 0;
foreach ($count as $key => $value)
{
  echo '<a class="normaltext" href="' . $scripturl . '?action=profile;u=' . $poster_number[$key] . '">' . $key . '</a> (' . $value . ')<br />';
  ++$list_number;
  if ($list_number > 9) 
    break;
}

RML

Thanks a lot. I was looking for something like that.  :)

WSA

It works great.  I use it to have a posting contest and I can see who has the most posts in a specific time frame.

Great snippet JP.

Xarcell

Nice snippet. Great for contests...

JPDeni

Thanks. I'm glad to help. I wouldn't have thought this would be something used a lot, but if it is, wonderful.

rebelrose

Can this be done counting everyone on the forum including admins and mods. To show the top say 5 posters with the number of post per person?

JPDeni

#6
Sure. That's easier to do than what I have above.

You want just a general top x number of posters, right? No time limit?


$numberofposters = 5; // You can change this to however many you want

require_once "SSI.php";
$top_posters = ssi_topPoster($numberofposters, "return");

foreach ($top_posters as $poster)
{
  echo $poster['link'] , ' (', $poster['posts'] , ')<br />';
}


Edited to make the variables a little neater.

rebelrose

That is perfect thank you

akulion

is it possible to have this code so that when a person reaches top posted count (becomes #1) the computer CD rom ejects and a pizza comes out of it?

rebelrose

Quote from: akulion on October 19, 2006, 04:32:29 PM
is it possible to have this code so that when a person reaches top posted count (becomes #1) the computer CD rom ejects and a pizza comes out of it?

Now that would be too cool