Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

August 19, 2022, 06:03:30 AM

Login with username, password and session length
Members
  • Total Members: 3843
  • Latest: Tricky
Stats
  • Total Posts: 193479
  • Total Topics: 21088
  • Online today: 58
  • Online ever: 1035
  • (November 26, 2020, 04:45:12 AM)
Users Online
Users: 1
Guests: 46
Total: 47

Author Topic: Top posters  (Read 58988 times)

0 Members and 1 Guest are viewing this topic.

JPDeni

  • Guest
Top posters
« on: September 20, 2006, 06:27:56 AM »
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.

Code: [Select]
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

  • Guest
Re: Top posters
« Reply #1 on: September 20, 2006, 07:08:53 AM »
Thanks a lot. I was looking for something like that.  :)

WSA

  • Guest
Re: Top posters
« Reply #2 on: September 20, 2006, 08:50:58 AM »
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

  • Guest
Re: Top posters
« Reply #3 on: September 20, 2006, 09:43:39 AM »
Nice snippet. Great for contests...

JPDeni

  • Guest
Re: Top posters
« Reply #4 on: September 20, 2006, 09:47:03 AM »
Thanks. I'm glad to help. I wouldn't have thought this would be something used a lot, but if it is, wonderful.

Offline rebelrose

  • Friends
  • *
  • Posts: 945
Re: Top posters
« Reply #5 on: October 18, 2006, 05:15:22 PM »
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

  • Guest
Re: Top posters
« Reply #6 on: October 18, 2006, 06:58:12 PM »
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?

Code: [Select]
$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.
« Last Edit: October 18, 2006, 07:22:07 PM by JPDeni »

Offline rebelrose

  • Friends
  • *
  • Posts: 945
Re: Top posters
« Reply #7 on: October 18, 2006, 07:14:11 PM »
That is perfect thank you

akulion

  • Guest
Re: Top posters
« Reply #8 on: October 19, 2006, 09:32:29 AM »
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?

Offline rebelrose

  • Friends
  • *
  • Posts: 945
Re: Top posters
« Reply #9 on: October 19, 2006, 10:12:50 AM »
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