TinyPortal

Development => Block Codes => Topic started by: JPDeni on September 20, 2006, 01:27:56 PM

Title: Top posters
Post by: JPDeni on September 20, 2006, 01:27:56 PM
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 (http://www.onlineconversion.com/unix_time.htm), 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;
}
Title: Re: Top posters
Post by: RML on September 20, 2006, 02:08:53 PM
Thanks a lot. I was looking for something like that.  :)
Title: Re: Top posters
Post by: WSA on September 20, 2006, 03:50:58 PM
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.
Title: Re: Top posters
Post by: Xarcell on September 20, 2006, 04:43:39 PM
Nice snippet. Great for contests...
Title: Re: Top posters
Post by: JPDeni on September 20, 2006, 04:47:03 PM
Thanks. I'm glad to help. I wouldn't have thought this would be something used a lot, but if it is, wonderful.
Title: Re: Top posters
Post by: rebelrose on October 19, 2006, 12:15:22 AM
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?
Title: Re: Top posters
Post by: JPDeni on October 19, 2006, 01:58:12 AM
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.
Title: Re: Top posters
Post by: rebelrose on October 19, 2006, 02:14:11 AM
That is perfect thank you
Title: Re: Top posters
Post by: 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?
Title: Re: Top posters
Post by: rebelrose on October 19, 2006, 05:12:50 PM
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
Title: Re: Top posters
Post by: akulion on October 19, 2006, 05:13:36 PM
i thought i would give it a try in asking jpdeni - she seems to have codes for everything :D

so we might just get one yet!
Title: Re: Top posters
Post by: JPDeni on October 19, 2006, 05:16:48 PM
 :2funny: Well, I think you've got me stumped on that one, aku!!  :2funny:
Title: Re: Top posters
Post by: akulion on November 04, 2006, 03:06:52 AM
hey u know when u view the stats page (http://www.tinyportal.net/smf/index.php?action=stats) how they have those cool bar graphs alongside?

how would I include that in this?

thanks
Title: Re: Top posters
Post by: JPDeni on November 04, 2006, 03:57:53 AM
Oh, Aku. You always come up with something new. :)

I haven't tried this myself, but this seems like it would work.

First, add $settings to your global statement at the beginning of the code.

Then change

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;
}


to


$biggest = 0;
foreach ($count as $key => $value)
{
  if ($biggest == 0)
    $biggest = $value;
  $bar_length = intval(($value/$biggest) * 100);
  echo '<a class="normaltext" href="' . $scripturl . '?action=profile;u=' . $poster_number[$key] . '">' . $key . '</a> (' . $value . ')
<img src="' . $settings['images_url'] . '/bar.gif" width="' . $bar_length . '" height="15" alt="" /><br />';

  ++$list_number;
  if ($list_number > 9) 
    break;
}


The potential problem I see is that it might be too long, especially if you have this on a side block. The bar for the top poster will be 100 pixels long. If it turns out to be too long, change the 100 to something smaller.

Of course, it may not work at all. :)
Title: Re: Top posters
Post by: akulion on November 04, 2006, 04:01:45 AM
Cool :D thanks :D

ill try it out until I can think of more things to ask :2funny:

Thank you very much :up:
Title: Re: Top posters
Post by: JPDeni on November 04, 2006, 04:03:49 AM
My pleasure. :)
Title: Re: Top posters
Post by: akulion on November 04, 2006, 04:08:29 AM
got an error:

Quote
Parse error: syntax error, unexpected '>' in /home/.cash/akulion/goofy-goobers.com/forum/Sources/Load.php(1715) : eval()'d code(35) : eval()'d code on line 34
Title: Re: Top posters
Post by: JPDeni on November 04, 2006, 05:09:12 AM
Sorry. There was an extra apostrophe in the code. I'll go change it.
Title: Re: Top posters
Post by: akulion on November 04, 2006, 05:17:11 AM
aaahhh now it works very nicely!!

I like the cool mouse over effects with the popup java box and the flashing symbols :up:

thanks :D
Title: Re: Top posters
Post by: Tron420 on December 03, 2006, 02:17:57 PM
i tried it but all that shows up in the block is the code.
what am i doing wrong?
Title: Re: Top posters
Post by: IchBin on December 03, 2006, 03:33:06 PM
What kind of block are you using?
Title: Re: Top posters
Post by: Tron420 on December 03, 2006, 03:34:15 PM
no html seems to work in my bbc-html blocks
Title: Re: Top posters
Post by: IchBin on December 03, 2006, 03:37:50 PM
You're supposed to put this code in a phpbox.
Title: Re: Top posters
Post by: Tron420 on December 03, 2006, 03:42:44 PM
ok ill try that
Title: Re: Top posters
Post by: Tron420 on December 03, 2006, 03:47:44 PM
great it works now. thx
why doesnt the html work in a bbc-html block?
all that shows up is the code
Title: Re: Top posters
Post by: G6Cad on December 03, 2006, 03:58:12 PM
Please, do NOT crosspost the same questions, it's hard for us to keep track on things if you crosspost.
Title: Re: Top posters
Post by: Tron420 on December 03, 2006, 05:08:20 PM
sry
Title: Re: Top posters
Post by: deniz on January 01, 2007, 10:43:48 PM
i dont want specific time frame with start and end time.

is it possible top posters, topics for "last 7 days"
Title: Re: Top posters
Post by: deniz on January 06, 2007, 09:40:39 PM
i did top posters for last 7 days:

change:

$starttime = time() - 604800;
$endtime = time ();

Title: Re: Top posters
Post by: Shadow on January 06, 2007, 10:14:28 PM
This code should work for you ok.  I am using this code on my forum too.  This code isn't mine at all. RebelRose put the code in for me..SO thank's to RebelRose

Use this block (phpbox) for this code

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


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

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


This code last forever...
Title: Re: Top posters
Post by: Gargoyle on January 07, 2007, 03:48:19 AM
First of all I LOVE this code!!

Second I would like to request a change...

I have a few users that registered under one name but then changed it later to a name they liked more. Now this block displays their "account" name but not the name they use in the rest of the forum. Is there a way to make it display their "used" name instead of the "account" name ??

Thanks!!
Title: Re: Top posters
Post by: stormlrd on January 07, 2007, 04:06:33 AM
nice snippet i might add it too some of my stuff. try using mktime() format for your dates it will make it easier to understand.

mktime(0,0,0,1,10,07)

Description
int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )

http://us3.php.net/manual/en/function.mktime.php

Title: Re: Top posters
Post by: Gargoyle on January 07, 2007, 07:52:17 PM
I figured it out...

Thanks for the code!!!
Title: Re: Top posters
Post by: sbm on January 14, 2007, 07:09:06 PM
really a nice script....
Title: Re: Top posters
Post by: Shadow on January 20, 2007, 12:33:56 AM
I love this code very much...
Title: Re: Top posters
Post by: jdvarner on February 13, 2007, 03:25:44 PM
how would i make the original one posted "time based" include the admin as well?
Title: Re: Top posters
Post by: JPDeni on February 13, 2007, 04:39:03 PM
By "orginial one posted" I'm assuming you mean the one in the first post. :) To include everyone, delete


     WHERE ID_GROUP <> 1 AND ID_GROUP <> 2


from the query.

I'm not sure what you mean by "time based."
Title: Re: Top posters
Post by: jdvarner on February 14, 2007, 01:04:20 AM
awesome. thank you. by time based, i meant the first post as you mentioned that was for counting post by the unix time stamp. thanks. :)
Title: Re: Top posters
Post by: jdvarner on February 14, 2007, 01:21:28 AM
I love this bloc. Its awesome. I have a question... kind of related to the way this one works. Can it be coded to pull name and top 5 high rank person out of the member list? I do my members rank by post count and its all military rank. :)

couple of posts is a private, more posts and you move up of course. Just curious if this was possible, and i figured it was kind of related and thought i'd ask. Just would be cool to show top 5 highest ranked persons on the site. Just an idea.

Hey thanks all for your great bloc's, and responses. Love the site and this board.

John
Title: Re: Top posters
Post by: JPDeni on February 14, 2007, 01:35:26 AM
The block isn't intended to do what you want. There's actually another function built-in to do what you want, I think, if I understand what it is that you want. It would probably have to be combined with the ranks table, which could be done.

At any rate, it's a completely different code than I wrote here.
Title: Re: Top posters
Post by: jdvarner on February 14, 2007, 01:39:24 AM
I understand. Thank You. Im not a good guy with codes, so thought i'd ask the professionals. :)

Title: Re: Top posters
Post by: Shadow on February 14, 2007, 04:55:10 AM
Which code is that? 
Title: Re: Top posters
Post by: jdvarner on February 14, 2007, 05:22:41 AM
Quote from: Shadow Queen on February 14, 2007, 04:55:10 AM
Which code is that? 

This is what i had asked...

Can it be coded to pull name and top 5 high rank person out of the member list? I do my members rank by post count and its all military rank.

couple of posts is a private, more posts and you move up of course. Just curious if this was possible, and i figured it was kind of related and thought i'd ask. Just would be cool to show top 5 highest ranked persons on the site. Just an idea.

Hey thanks all for your great bloc's, and responses. Love the site and this board.

John

John
Title: Re: Top posters
Post by: Shadow on February 14, 2007, 05:55:56 AM
Here a pic you can see

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fimg165.imageshack.us%2Fimg165%2F8972%2Funtitlediw7.th.jpg&hash=6d820dae4f4fe9fdcc5beaf1f57043b2c08c4ecb) (http://img165.imageshack.us/my.php?image=untitlediw7.jpg)

I really don't know if the code can do that or what...
Title: Re: Top posters
Post by: Sledge HaMMeR on March 30, 2007, 02:12:46 AM
I'm back JPDeni  :o

I've combined some code from this topic to
- php side block (180 pixels)
- last week top posters
- used gfx-bars
- include admins/mods

global $db_prefix, $scripturl, $settings;

// $starttime = 1167609601; // Change this to the time you want the contest to start [http://www.onlineconversion.com/unix_time.htm]
// $endtime = 1199145601;  // Change this to the time you want the contest to end

$starttime = time() - 604800; // Last week posters
$endtime = time ();

$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
     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;
$biggest = 0;
foreach ($count as $key => $value)
{
  if ($biggest == 0)
    $biggest = $value;
  $bar_length = intval(($value/$biggest) * 40);
  echo '
  <table width="100%" border="0">
  <tr>
    <td><div class="smalltext"><a href="' . $scripturl . '?action=profile;u=' . $poster_number[$key] . '">' . $key . '</a> (' . $value . ')</div></td>
    <td><div align="right"><img src="' . $settings['images_url'] . '/bar.gif" width="' . $bar_length . '" height="10" alt="" /></div></td>
  </tr>
</table>
  ';

  ++$list_number;
  if ($list_number > 4) 
    break;
}



but I have the same question as Gargoyle
Quote from: Gargoyle on January 07, 2007, 03:48:19 AM
I have a few users that registered under one name but then changed it later to a name they liked more. Now this block displays their "account" name but not the name they use in the rest of the forum. Is there a way to make it display their "used" name instead of the "account" name ??

I would like to echo the 'realName' from '{$db_prefix}members'
I assume it's not very tough, but I'm nothing like a php/db guru

tnx in advange
Title: Re: Top posters
Post by: JPDeni on March 30, 2007, 03:08:47 AM
Change every instance of posterName to realName.
Title: Re: Top posters
Post by: Sledge HaMMeR on March 30, 2007, 03:21:56 AM
Damn, it works.
I figured that was too easy because '{$db_prefix}messages' does not use 'realName'.

Tnx, it works perfect on our site.
Title: Re: Top posters
Post by: JPDeni on March 30, 2007, 03:38:52 AM
Quote'{$db_prefix}messages' does not use 'realName'
Right. But '{$db_prefix}members' has it and the query joins the two tables on the ID_MEMBER field.

You're welcome. Glad I could help. :)
Title: Re: Top posters
Post by: Shadow on March 30, 2007, 03:39:51 AM
I try that code in a phpbox and it's didn't show up for me at all. 
Title: Re: Top posters
Post by: KiChU on April 22, 2007, 06:47:19 PM
Quote$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'] , ')
';

Am Using this code , but it is not displaying the member group color.
Can u tell me the code for it ??
Title: Re: Top posters
Post by: TexasBartender on May 08, 2007, 07:50:53 AM
Quote from: Sledge HaMMeR on March 30, 2007, 02:12:46 AM
I'm back JPDeni  :o

I've combined some code from this topic to
- php side block (180 pixels)
- last week top posters
- used gfx-bars
- include admins/mods

global $db_prefix, $scripturl, $settings;

// $starttime = 1167609601; // Change this to the time you want the contest to start [http://www.onlineconversion.com/unix_time.htm]
// $endtime = 1199145601;  // Change this to the time you want the contest to end

$starttime = time() - 604800; // Last week posters
$endtime = time ();

$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
     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;
$biggest = 0;
foreach ($count as $key => $value)
{
  if ($biggest == 0)
    $biggest = $value;
  $bar_length = intval(($value/$biggest) * 40);
  echo '
  <table width="100%" border="0">
  <tr>
    <td><div class="smalltext"><a href="' . $scripturl . '?action=profile;u=' . $poster_number[$key] . '">' . $key . '</a> (' . $value . ')</div></td>
    <td><div align="right"><img src="' . $settings['images_url'] . '/bar.gif" width="' . $bar_length . '" height="10" alt="" /></div></td>
  </tr>
</table>
  ';

  ++$list_number;
  if ($list_number > 4) 
    break;
}



but I have the same question as Gargoyle
Quote from: Gargoyle on January 07, 2007, 03:48:19 AM
I have a few users that registered under one name but then changed it later to a name they liked more. Now this block displays their "account" name but not the name they use in the rest of the forum. Is there a way to make it display their "used" name instead of the "account" name ??

I would like to echo the 'realName' from '{$db_prefix}members'
I assume it's not very tough, but I'm nothing like a php/db guru

tnx in advange

This is the only code in this topic that works for me so my question is how to add change it from 5 members and how do I take it to where admins and mods don't count
Title: Re: Top posters
Post by: Thief on May 11, 2007, 02:18:46 PM
I have modified top posters script(s) posted here to support member color links if they are available. Also removed some redundant code.
global $db_prefix, $scripturl, $modSettings;

$memberstoshow = 7;
$matchperiod = false;
$countmodsandadmins = true; // not yet implemented
// Change this to the time you want the contest to start [http://www.onlineconversion.com/unix_time.htm]
$starttime = time() - 604800; // Last week posters
$endtime = time();  // Change this to the time you want the contest to end
$where_period = '';

if (!empty($modSettings['MemberColorLink'])) // check if MemberColorLink mod is installed and enabled         
{
    if ($matchperiod) // select only posts matching period
        $where_period = "AND m.posterTime > $starttime AND m.posterTime < $endtime";
    $query = db_query(
        "SELECT m.realName, m.ID_MEMBER, mg.onlineColor, m.posts
         FROM {$db_prefix}members AS m
         LEFT JOIN {$db_prefix}membergroups AS mg ON (m.ID_GROUP = mg.ID_GROUP AND m.ID_GROUP)
         $where_period
         ORDER BY m.posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}
else
{
    if ($matchperiod) // select only posts matching period
        $where_period = "WHERE posterTime > $starttime AND posterTime < $endtime";
    $query = db_query(
        "SELECT realName, ID_MEMBER, posts
         FROM {$db_prefix}members
         $where_period
         ORDER BY posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}

$firstrecord = true;
while ($row = mysql_fetch_assoc($query))
{
    if ($firstrecord)
    {
        $biggest = $row['posts'];
        $firstrecord = false;
    }
    $bar_length = intval(($row['posts']/$biggest) * 40);

    if(isset($row['onlineColor']))
        $style = 'color: '. $row['onlineColor'];
    else
        $style = '';

    echo '
    <table width="100%" border="0">
    <tr>
    <td><div class="smalltext"><b><a style="' . $style . '" href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a></b> (' . $row['posts'] . ')</div></td>
    <td><div align="right"><img src="' . $settings['images_url'] . '/bar.gif" width="' . $bar_length . '" height="10" title="' . $bar_length*2.5 . '%" alt="" /></div></td>
    </tr>
    </table>
    ';
}


Please post comments and suggestions so I will be able to improve it for your needs :) Thanks.
Title: Re: Top posters
Post by: Zetan on May 11, 2007, 02:29:37 PM
Brilliant  :up: I've had Top Ten posters on my site for ages.. Just used you're script and it looks and works a treat... Thanks  8)
Title: Re: Top posters
Post by: jdvarner on May 11, 2007, 03:09:36 PM
Theif, get this error when using yours:

8: Undefined variable: starttime
File: /home/content/j/d/w/jdworld/html/Themes/default/languages/Arcade.english.php (eval?)
Line: 28
Title: Re: Top posters
Post by: Thief on May 11, 2007, 03:17:31 PM
Zetan, thanks for such a positive feedback, my pleasure reading it. cheers!

jdvarner, thanks for info, should be fixed now. please check.
Title: Re: Top posters
Post by: Zetan on May 11, 2007, 03:43:01 PM
Just checked my logs.. had the same error.
I'm getting this error still:

Quote8: Undefined variable: where
File: /home/zetan/public_html/Themes/default/languages/Stats.english.php (eval?)
Line: 23

[Edit] I'm assuming that its the Top Posters causing it.. I'll turn it off and check.
Title: Re: Top posters
Post by: Thief on May 11, 2007, 03:46:57 PM
Sorry guys, its hard for me to write code without "notice" errors, but I'm trying..
please check updated block code. if it won't help I'll rewrite part about period match.
[edit] Zetan, yeah its my bad code causes this, no doubts :P
[edit2] one more code change.
Title: Re: Top posters
Post by: Zetan on May 11, 2007, 04:47:13 PM
 :) That seems to have fixed it now. No errors.
Title: Re: Top posters
Post by: jdvarner on May 11, 2007, 10:45:51 PM
I still get the errors thief. Not sure why. Im not changing any of the code. Just copy and paste. I checked to make sure i have no errors prior to block creation and then i put the code and check the log and it fills up in seconds. I'll keep it on deactive for a bit.
Title: Re: Top posters
Post by: Thief on May 11, 2007, 10:59:25 PM
what errors are you having, jdvarner? the same?
Title: Re: Top posters
Post by: jdvarner on May 11, 2007, 11:02:40 PM
same
Title: Re: Top posters
Post by: Thief on May 11, 2007, 11:05:18 PM
Okay, I've updated (http://www.tinyportal.net/index.php?topic=8762.msg131637#msg131637) code once again. Hopefully it will shutdown those notices :)
(By the way I don't see any errors at my forum logs)

[edit] one more - fixes incorrect percent display on hovering bars.
[edit2] fixed - members without group (thus color) weren't shown. sql fixes. increased default member count to "7" as well.
Title: Re: Top posters
Post by: jdvarner on May 12, 2007, 03:44:10 AM
must be my site and or my additional mods. still getting error (different one now) and i dont see any color difference even though there should be.

2: mysql_result(): Unable to jump to row 0 on MySQL result index 57
File: /home/content/j/d/w/jdworld/html/Themes/default/languages/Arcade.english.php (eval?)
Line: 16
Title: Re: Top posters
Post by: Thief on May 12, 2007, 09:05:48 AM
Wait, now it doesn't show top posters at all, right?
Do you have Member Color Link mod installed?
Title: Re: Top posters
Post by: Zetan on May 12, 2007, 10:34:21 AM
From my last error check, I had none from this snippit, I've just checked again since the updates you've made and I have no errors

QuoteForum Error Log
The error log tracks every error encountered by your forum. To delete any errors from the database, mark the checkbox, and click the Remove button at the bottom of the page.
Pages: [1]
No messages...
Pages: [1]
Title: Re: Top posters
Post by: Thief on May 12, 2007, 03:47:35 PM
jdvarner, I assume that you haven't MemberColorLink mod installed and because code to check if it is available was really lame you were getting that error.
Now I did a proper check (I hope so, I'm not much a Tinyportal expert), so this issue should be solved.
Please check updated code (http://www.tinyportal.net/index.php?topic=8762.msg131637#msg131637) and let me know if my assumptions are correct. Thanks.
Title: Re: Top posters
Post by: CyberOPs on May 12, 2007, 04:54:29 PM
Im using the following code and it works great but when someone has a longer name the post count ends up under their name is there anything i can do to change that ?

global $db_prefix, $scripturl, $memberContext, $txt, $modSettings;

// $starttime = strtotime('24 hours ago'); //posters laatste 24 uur
$starttime = mktime(0, 0, 0, date('m'), date('d'), date('Y')); //posters vandaag
$list_count = 10;

$poster = array();

$request = db_query("
SELECT  m.ID_MEMBER, COUNT(m.ID_MEMBER) as postCount
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b)
WHERE m.posterTime > " . $starttime . "
AND t.ID_TOPIC = m.ID_TOPIC
AND b.ID_BOARD = t.ID_BOARD" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? " AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
GROUP BY m.ID_MEMBER
ORDER BY postCount DESC LIMIT " . $list_count, __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($request))
{
    loadMemberData(array($row['ID_MEMBER']));
    loadMemberContext($row['ID_MEMBER']);
$poster[$row['ID_MEMBER']] = array (
  'id' => $row['ID_MEMBER'],
  'count' => $row['postCount'],
  'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '" title="' . $txt[92] . ' ' . $memberContext[$row['ID_MEMBER']]['name'] . '">' . '<font color="' . $memberContext[$row['ID_MEMBER']]['group_color'] . '">' . $memberContext[$row['ID_MEMBER']]['name'] . '</font>' . '</a>' );
}
mysql_free_result($request);

echo '<table width=100%>';
foreach($poster as $top_user)
{
echo '<tr>
      <td align="right" width=75%>' . $top_user['link'] . '</td>
      <td align="left">| '. $top_user['count'] . '</td>
      </tr>';
}
echo '</table>';
Title: Re: Top posters
Post by: Thief on May 12, 2007, 05:15:58 PM
well, you can try to increase rows width. You have:
width=75%
Title: Re: Top posters
Post by: CyberOPs on May 12, 2007, 05:25:41 PM
already tried that with no luck
Title: Re: Top posters
Post by: Thief on May 12, 2007, 05:33:42 PM
hmm, then sorry no idea why it can wrap. can you provide screenshot/link to site?
Title: Re: Top posters
Post by: CyberOPs on May 12, 2007, 09:13:04 PM
well it would already help if you could somehow set the max size of the names, so if there is anywat to do this
Title: Re: Top posters
Post by: jdvarner on May 13, 2007, 06:14:40 AM
yup that did it thief. thanks.
Title: Re: Top posters
Post by: jdvarner on May 13, 2007, 06:19:59 AM
thief, i install member color mod, but dont see a difference. did i have to activate that in admin panel? just asking. not trying to change topic of your thread here. but it kind of goes with your mod and thought i'd ask since you suggested the mod.

jd
Title: Re: Top posters
Post by: Thief on May 13, 2007, 06:37:47 AM
CyberOPs,
you can try to define maxlength:
$maxlength=20;
and then, using function substr (http://ua2.php.net/manual/en/function.substr.php), code like this:

$membername = (strlen($memberContext[$row['ID_MEMBER']]['name'])) > $maxlength) substr($memberContext[$row['ID_MEMBER']]['name']),0,$maxlength) : $memberContext[$row['ID_MEMBER']]['name'];


jdvarner,
Quote from: jdvarner on May 13, 2007, 06:14:40 AM
yup that did it thief. thanks.
glad to hear that :) you are wellcome
and yes, my code checks if Member color link mod enabled.
Title: Re: Top posters
Post by: CyberOPs on May 13, 2007, 03:11:44 PM
how would i put that in thief im not that good with all the coding could you maybe post a modified code from what i posted ?
Title: Re: Top posters
Post by: Thief on May 13, 2007, 07:08:18 PM
not tested:
global $db_prefix, $scripturl, $memberContext, $txt, $modSettings;
$maxlength=20;

// $starttime = strtotime('24 hours ago'); //posters laatste 24 uur
$starttime = mktime(0, 0, 0, date('m'), date('d'), date('Y')); //posters vandaag
$list_count = 10;

$poster = array();

$request = db_query("
SELECT  m.ID_MEMBER, COUNT(m.ID_MEMBER) as postCount
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b)
WHERE m.posterTime > " . $starttime . "
AND t.ID_TOPIC = m.ID_TOPIC
AND b.ID_BOARD = t.ID_BOARD" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? " AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
GROUP BY m.ID_MEMBER
ORDER BY postCount DESC LIMIT " . $list_count, __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($request))
{
    loadMemberData(array($row['ID_MEMBER']));
    loadMemberContext($row['ID_MEMBER']);
$membername = (strlen($memberContext[$row['ID_MEMBER']]['name']) > $maxlength) ? substr($memberContext[$row['ID_MEMBER']]['name'],0,$maxlength) : $memberContext[$row['ID_MEMBER']]['name'];
$poster[$row['ID_MEMBER']] = array (
  'id' => $row['ID_MEMBER'],
  'count' => $row['postCount'],
  'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '" title="' . $txt[92] . ' ' . $memberContext[$row['ID_MEMBER']]['name'] . '">' . '<font color="' . $memberContext[$row['ID_MEMBER']]['group_color'] . '">' . $membername . '</font>' . '</a>' );
}
mysql_free_result($request);

echo '<table width=100%>';
foreach($poster as $top_user)
{
echo '<tr>
      <td align="right" width=75%>' . $top_user['link'] . '</td>
      <td align="left">| '. $top_user['count'] . '</td>
      </tr>';
}
echo '</table>';
Title: Re: Top posters
Post by: CyberOPs on May 15, 2007, 12:08:25 AM
Thief it didn't work im getting some sort of error about the database
Title: Re: Top posters
Post by: Thief on May 15, 2007, 06:48:19 AM
Could you be more specific? It shoudn't change the way its working with database.
And please try updated code.
Title: Re: Top posters
Post by: CyberOPs on May 15, 2007, 10:10:56 AM
Parse error: syntax error, unexpected T_STRING in /home/Sources/Load.php(1735) : eval()'d code(35) : eval()'d code on line 23

that is the error i get even with the updated code

Title: Re: Top posters
Post by: Thief on May 15, 2007, 10:21:07 AM
should be fixed.
Title: Re: Top posters
Post by: CyberOPs on May 15, 2007, 04:07:05 PM
zo far it works thanks now it's just waiting for someone with a long name to come online lol, thanks for the help apreciate it very much.
Title: Re: Top posters
Post by: CyberOPs on May 15, 2007, 08:01:34 PM
Just wanted to let you know that it works great, again thanks for the time and work.
Title: Re: Top posters
Post by: Thief on May 15, 2007, 08:15:33 PM
You are wellcome, CyberOPs, cheers :)
Title: Re: Top posters
Post by: fangweile on May 23, 2007, 11:21:18 AM
This is really a very nice script:
Quote$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'] , ')
';
}

Would it be possible to show the color of the membergroup, the rank title and the rank image there.

Is anyone have script for that, thanks in advance


Title: Re: Top posters
Post by: Thief on May 23, 2007, 11:30:14 AM
My script (http://www.tinyportal.net/index.php?topic=8762.msg131637#msg131637) can show member colors (it can be done by modifing ssi_topPoster function too).
about the rank title and image - I can do that as well, just tell me how you want to see it, the layout.
Title: Re: Top posters
Post by: fangweile on May 23, 2007, 12:27:50 PM
thanks for your reply, I want the top poster just like this

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fimg511.imageshack.us%2Fimg511%2F5723%2Ftop10fa6.jpg&hash=2a16a42aee121dcf5543950947869d4846c29bcc)

hope you can help
Title: Re: Top posters
Post by: Thief on May 23, 2007, 01:29:27 PM
okay, I'll try to collect needed info. Do you know html to make such layout?
[edit] not sure what "Rank" means. Is it group name?
Title: Re: Top posters
Post by: fangweile on May 24, 2007, 01:48:57 AM
No, I didn't know the html code for that, Rank is the membergroup name just like Jr. Member with their no. of stars.
Title: Re: Top posters
Post by: confuzed on July 06, 2007, 05:01:30 PM
It is possible to add something to this script so that it only counted posts in certain boards for the duration of the contest?  (I know I can change the boards in admin CP to count posts or not but I dont want to change how that is set up.) I just want to have a competition for posting in certain boards for a period of time.

Is that possible and can someone tell me what code to use?
Title: Re: Top posters
Post by: IchBin on July 06, 2007, 10:34:13 PM
Quote from: confuzed on July 06, 2007, 05:01:30 PM
It is possible to add something to this script so that it only counted posts in certain boards for the duration of the contest?  (I know I can change the boards in admin CP to count posts or not but I dont want to change how that is set up.) I just want to have a competition for posting in certain boards for a period of time.

Is that possible and can someone tell me what code to use?

This would be a SMF mod. You should check their for something similar. If you don't find something, post a request in the Code help boards.
Title: Re: Top posters
Post by: confuzed on July 16, 2007, 12:29:03 AM
thanks.

Question does this code use the time that the board is set to or the time on the server that the board is on?  Because that would be a problem :(
Title: Re: Top posters
Post by: IchBin on July 16, 2007, 02:02:47 AM
It uses the time you set at the beginning of the script. If you read the comments you will see.
Title: Re: Top posters
Post by: insanemustang on December 29, 2007, 02:39:17 AM
What if you wanted to take this and say, "Top posters for today..."
Title: Re: Top posters
Post by: texasflats on December 31, 2007, 03:00:06 AM
Thief,
I'm using your code, and it works great, so thanks!
One question, how do I exclude admins and moderators from being counted?
Thanks again.

Quote from: Thief on May 11, 2007, 02:18:46 PM
I have modified top posters script(s) posted here to support member color links if they are available. Also removed some redundant code.
global $db_prefix, $scripturl, $modSettings;

$memberstoshow = 7;
$matchperiod = false;
$countmodsandadmins = true; // not yet implemented
// Change this to the time you want the contest to start [http://www.onlineconversion.com/unix_time.htm]
$starttime = time() - 604800; // Last week posters
$endtime = time();  // Change this to the time you want the contest to end
$where_period = '';

if (!empty($modSettings['MemberColorLink'])) // check if MemberColorLink mod is installed and enabled         
{
    if ($matchperiod) // select only posts matching period
        $where_period = "AND m.posterTime > $starttime AND m.posterTime < $endtime";
    $query = db_query(
        "SELECT m.realName, m.ID_MEMBER, mg.onlineColor, m.posts
         FROM {$db_prefix}members AS m
         LEFT JOIN {$db_prefix}membergroups AS mg ON (m.ID_GROUP = mg.ID_GROUP AND m.ID_GROUP)
         $where_period
         ORDER BY m.posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}
else
{
    if ($matchperiod) // select only posts matching period
        $where_period = "WHERE posterTime > $starttime AND posterTime < $endtime";
    $query = db_query(
        "SELECT realName, ID_MEMBER, posts
         FROM {$db_prefix}members
         $where_period
         ORDER BY posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}

$firstrecord = true;
while ($row = mysql_fetch_assoc($query))
{
    if ($firstrecord)
    {
        $biggest = $row['posts'];
        $firstrecord = false;
    }
    $bar_length = intval(($row['posts']/$biggest) * 40);

    if(isset($row['onlineColor']))
        $style = 'color: '. $row['onlineColor'];
    else
        $style = '';

    echo '
    <table width="100%" border="0">
    <tr>
    <td><div class="smalltext"><b><a style="' . $style . '" href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a></b> (' . $row['posts'] . ')</div></td>
    <td><div align="right"><img src="' . $settings['images_url'] . '/bar.gif" width="' . $bar_length . '" height="10" title="' . $bar_length*2.5 . '%" alt="" /></div></td>
    </tr>
    </table>
    ';
}


Please post comments and suggestions so I will be able to improve it for your needs :) Thanks.
Title: Re: Top posters
Post by: insanemustang on January 02, 2008, 04:26:40 PM
Quote from: texasflats on December 31, 2007, 03:00:06 AM
Thief,
I'm using your code, and it works great, so thanks!
One question, how do I exclude admins and moderators from being counted?
Thanks again.

I too am interested in this.  Did you figure it out, I can't.
Title: Re: Top posters
Post by: IchBin on January 02, 2008, 04:47:26 PM
Headed out the door, so this was quick and untested. I'll check back later to see if it works.
global $db_prefix, $scripturl, $modSettings;

$memberstoshow = 7;
$matchperiod = false;
$countmodsandadmins = true; // not yet implemented
// Change this to the time you want the contest to start [http://www.onlineconversion.com/unix_time.htm]
$starttime = time() - 604800; // Last week posters
$endtime = time();  // Change this to the time you want the contest to end
$where_period = '';

if (!empty($modSettings['MemberColorLink'])) // check if MemberColorLink mod is installed and enabled         
{
    if ($matchperiod) // select only posts matching period
        $where_period = "AND m.posterTime > $starttime AND m.posterTime < $endtime";
    $query = db_query(
        "SELECT m.realName, m.ID_GROUP, m.ID_MEMBER, mg.onlineColor, m.posts
         FROM {$db_prefix}members AS m
         LEFT JOIN {$db_prefix}membergroups AS mg ON (m.ID_GROUP = mg.ID_GROUP AND m.ID_GROUP)
         $where_period
         ORDER BY m.posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}
else
{
    if ($matchperiod) // select only posts matching period
        $where_period = "WHERE posterTime > $starttime AND posterTime < $endtime";
    $query = db_query(
        "SELECT realName, ID_GROUP, ID_MEMBER, posts
         FROM {$db_prefix}members
         $where_period
         ORDER BY posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}

$firstrecord = true;
while ($row = mysql_fetch_assoc($query))
{
// Change the ID_GROUP 1 and 2 here to match the groups you don't want in the output
if ($row['ID_GROUP'] != 1 && $row['ID_GROUP'] != 2)
{
if ($firstrecord)
    {
        $biggest = $row['posts'];
        $firstrecord = false;
    }
    $bar_length = intval(($row['posts']/$biggest) * 40);

    if(isset($row['onlineColor']))
        $style = 'color: '. $row['onlineColor'];
    else
        $style = '';
}
    echo '
    <table width="100%" border="0">
    <tr>
    <td><div class="smalltext"><b><a style="' . $style . '" href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a></b> (' . $row['posts'] . ')</div></td>
    <td><div align="right"><img src="' . $settings['images_url'] . '/bar.gif" width="' . $bar_length . '" height="10" title="' . $bar_length*2.5 . '%" alt="" /></div></td>
    </tr>
    </table>
    ';
}


I put a comment in the code on what you need to change. So please read the code comment I put in there.
Title: Re: Top posters
Post by: insanemustang on January 02, 2008, 10:25:44 PM
Quote from: IchBinâ,,¢ on January 02, 2008, 04:47:26 PM
Headed out the door, so this was quick and untested. I'll check back later to see if it works.
global $db_prefix, $scripturl, $modSettings;

$memberstoshow = 7;
$matchperiod = false;
$countmodsandadmins = true; // not yet implemented
// Change this to the time you want the contest to start [http://www.onlineconversion.com/unix_time.htm]
$starttime = time() - 604800; // Last week posters
$endtime = time();  // Change this to the time you want the contest to end
$where_period = '';

if (!empty($modSettings['MemberColorLink'])) // check if MemberColorLink mod is installed and enabled         
{
    if ($matchperiod) // select only posts matching period
        $where_period = "AND m.posterTime > $starttime AND m.posterTime < $endtime";
    $query = db_query(
        "SELECT m.realName, m.ID_GROUP, m.ID_MEMBER, mg.onlineColor, m.posts
         FROM {$db_prefix}members AS m
         LEFT JOIN {$db_prefix}membergroups AS mg ON (m.ID_GROUP = mg.ID_GROUP AND m.ID_GROUP)
         $where_period
         ORDER BY m.posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}
else
{
    if ($matchperiod) // select only posts matching period
        $where_period = "WHERE posterTime > $starttime AND posterTime < $endtime";
    $query = db_query(
        "SELECT realName, ID_GROUP, ID_MEMBER, posts
         FROM {$db_prefix}members
         $where_period
         ORDER BY posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}

$firstrecord = true;
while ($row = mysql_fetch_assoc($query))
{
// Change the ID_GROUP 1 and 2 here to match the groups you don't want in the output
if ($row['ID_GROUP'] != 1 && $row['ID_GROUP'] != 2)
{
if ($firstrecord)
    {
        $biggest = $row['posts'];
        $firstrecord = false;
    }
    $bar_length = intval(($row['posts']/$biggest) * 40);

    if(isset($row['onlineColor']))
        $style = 'color: '. $row['onlineColor'];
    else
        $style = '';
}
    echo '
    <table width="100%" border="0">
    <tr>
    <td><div class="smalltext"><b><a style="' . $style . '" href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a></b> (' . $row['posts'] . ')</div></td>
    <td><div align="right"><img src="' . $settings['images_url'] . '/bar.gif" width="' . $bar_length . '" height="10" title="' . $bar_length*2.5 . '%" alt="" /></div></td>
    </tr>
    </table>
    ';
}


I put a comment in the code on what you need to change. So please read the code comment I put in there.

I copied and pasted this and it did not work... I read the comment, but I was unsure what to change.  Sorry for my low-level of php understanding.
Title: Re: Top posters
Post by: jdvarner on January 02, 2008, 10:52:36 PM
insane, looks as if you just need to put in time stamp of contest start and stop as per note.

here is link to convert and get those digits...

http://www.onlineconversion.com/unix_time.htm
Title: Re: Top posters
Post by: insanemustang on January 03, 2008, 02:26:21 AM
I don't want it to stop or start, i just want it to display the top posters - minus the administrators and moderators.
Title: Re: Top posters
Post by: jdvarner on January 03, 2008, 02:29:16 AM
oops. got you confused with the contest time frame request. :)
Title: Re: Top posters
Post by: insanemustang on January 03, 2008, 03:39:38 AM
:( help lol
Title: Re: Top posters
Post by: texasflats on January 03, 2008, 02:04:44 PM
I tried it also, it still shows Mods and Admins. But I DO appreciate the effort!

Quote from: IchBinâ,,¢ on January 02, 2008, 04:47:26 PM
Headed out the door, so this was quick and untested. I'll check back later to see if it works.
global $db_prefix, $scripturl, $modSettings;

$memberstoshow = 7;
$matchperiod = false;
$countmodsandadmins = true; // not yet implemented
// Change this to the time you want the contest to start [http://www.onlineconversion.com/unix_time.htm]
$starttime = time() - 604800; // Last week posters
$endtime = time();  // Change this to the time you want the contest to end
$where_period = '';

if (!empty($modSettings['MemberColorLink'])) // check if MemberColorLink mod is installed and enabled         
{
    if ($matchperiod) // select only posts matching period
        $where_period = "AND m.posterTime > $starttime AND m.posterTime < $endtime";
    $query = db_query(
        "SELECT m.realName, m.ID_GROUP, m.ID_MEMBER, mg.onlineColor, m.posts
         FROM {$db_prefix}members AS m
         LEFT JOIN {$db_prefix}membergroups AS mg ON (m.ID_GROUP = mg.ID_GROUP AND m.ID_GROUP)
         $where_period
         ORDER BY m.posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}
else
{
    if ($matchperiod) // select only posts matching period
        $where_period = "WHERE posterTime > $starttime AND posterTime < $endtime";
    $query = db_query(
        "SELECT realName, ID_GROUP, ID_MEMBER, posts
         FROM {$db_prefix}members
         $where_period
         ORDER BY posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}

$firstrecord = true;
while ($row = mysql_fetch_assoc($query))
{
// Change the ID_GROUP 1 and 2 here to match the groups you don't want in the output
if ($row['ID_GROUP'] != 1 && $row['ID_GROUP'] != 2)
{
if ($firstrecord)
    {
        $biggest = $row['posts'];
        $firstrecord = false;
    }
    $bar_length = intval(($row['posts']/$biggest) * 40);

    if(isset($row['onlineColor']))
        $style = 'color: '. $row['onlineColor'];
    else
        $style = '';
}
    echo '
    <table width="100%" border="0">
    <tr>
    <td><div class="smalltext"><b><a style="' . $style . '" href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a></b> (' . $row['posts'] . ')</div></td>
    <td><div align="right"><img src="' . $settings['images_url'] . '/bar.gif" width="' . $bar_length . '" height="10" title="' . $bar_length*2.5 . '%" alt="" /></div></td>
    </tr>
    </table>
    ';
}


I put a comment in the code on what you need to change. So please read the code comment I put in there.
Title: Re: Top posters
Post by: IchBin on January 03, 2008, 10:01:22 PM
The numbers 1 and 2 in this code are the ID numbers for your groups in SMF that you DON'T want to show. You can get the ID number by hovering your mouse over the link in the member groups section of your admin. Just exchange your numbers with these numbers.

Change this line:
if ($row['ID_GROUP'] != 1 && $row['ID_GROUP'] != 2)

To this:
if ($row['ID_GROUP'] != 1 || $row['ID_GROUP'] != 2)

See if this works. Still haven't had a chance to test it as I'm at work.
Title: Re: Top posters
Post by: texasflats on January 04, 2008, 01:12:53 AM
I'm sorry, I should have mentioned that I, well in fact 1 and 2 were the membergroups I wanted to exclude.

Thanks again.
Title: Re: Top posters
Post by: IchBin on January 04, 2008, 03:21:33 AM
So based on your last message, I have no idea whether its working for you or not...lol
Title: Re: Top posters
Post by: insanemustang on January 04, 2008, 05:29:18 AM
Ich, I put this

if ($row['ID_GROUP'] != 1 || $row['ID_GROUP'] != 2) into the spot, and it still has admins and moderators included in the list. 

Thank you for trying to help, I know you will figure it out.
Title: Re: Top posters
Post by: texasflats on January 04, 2008, 04:50:35 PM
lol sorry... No it didn't work.

Quote from: IchBinâ,,¢ on January 04, 2008, 03:21:33 AM
So based on your last message, I have no idea whether its working for you or not...lol
Title: Re: Top posters
Post by: IchBin on January 04, 2008, 11:23:23 PM
Ok, lemme think on this for a bit. Don't know why it wouldn't work. Maybe I'll try an array later to see if it makes a difference. Bring the topic up if you don't see something by the end of Saturday.
Title: Re: Top posters
Post by: IchBin on January 05, 2008, 02:17:07 AM
Well fork me sideways, it worked on my site with this code. Which seems to be the same as I posted above. Can you try this please.

global $db_prefix, $scripturl, $modSettings;

$memberstoshow = 7;
$matchperiod = false;
$countmodsandadmins = true; // not yet implemented
// Change this to the time you want the contest to start [http://www.onlineconversion.com/unix_time.htm]
$starttime = time() - 604800; // Last week posters
$endtime = time();  // Change this to the time you want the contest to end
$where_period = '';

if (!empty($modSettings['MemberColorLink'])) // check if MemberColorLink mod is installed and enabled         
{
    if ($matchperiod) // select only posts matching period
        $where_period = "AND m.posterTime > $starttime AND m.posterTime < $endtime";
    $query = db_query(
        "SELECT m.realName, m.ID_GROUP, m.ID_MEMBER, mg.onlineColor, m.posts
         FROM {$db_prefix}members AS m
         LEFT JOIN {$db_prefix}membergroups AS mg ON (m.ID_GROUP = mg.ID_GROUP AND m.ID_GROUP)
         $where_period
         ORDER BY m.posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}
else
{
    if ($matchperiod) // select only posts matching period
        $where_period = "WHERE posterTime > $starttime AND posterTime < $endtime";
    $query = db_query(
        "SELECT realName, ID_GROUP, ID_MEMBER, posts
         FROM {$db_prefix}members
         $where_period
         ORDER BY posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}

$firstrecord = true;

while ($row = mysql_fetch_assoc($query))
{
// Change the ID_GROUP 1 and 2 here to match the groups you don't want in the output
if ($row['ID_GROUP'] != 1 && $row['ID_GROUP'] != 2)
{
if ($firstrecord)
    {
        $biggest = $row['posts'];
        $firstrecord = false;
    }
    $bar_length = intval(($row['posts']/$biggest) * 40);

    if(isset($row['onlineColor']))
        $style = 'color: '. $row['onlineColor'];
    else
        $style = '';

    echo '
    <table width="100%" border="0">
    <tr>
    <td><div class="smalltext"><b><a style="' . $style . '" href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a></b> (' . $row['posts'] . ')</div></td>
    <td><div align="right"><img src="' . $settings['images_url'] . '/bar.gif" width="' . $bar_length . '" height="10" title="' . $bar_length*2.5 . '%" alt="" /></div></td>
    </tr>
    </table>';
    }
}
Title: Re: Top posters
Post by: insanemustang on January 06, 2008, 10:36:03 PM
Ich your a genius.  Thank you sir.
Title: Re: Top posters
Post by: texasflats on January 07, 2008, 07:54:36 PM
The last one works for me also, thank you IchBinâ,,¢
Title: Re: Top posters
Post by: jabroni pkp on January 08, 2008, 08:32:59 PM
threw this on our site today and have to say that its a quality block. thanks for putting it up
Title: Re: Top posters
Post by: nitishthelegendkiller on April 15, 2008, 10:45:05 AM
First of all, i really liked this script.I started a competition  in my site.I wanted certain members to be excluded.See, i have got 1 bot working from 1 id.I started top poster of the month comp. .That bot welcomes all the members(SMF welcome mod).So, i wanted that bot not to be displayed in the top posters.

Any help?
Title: Re: Top posters
Post by: JPDeni on April 15, 2008, 03:18:47 PM
I assume from your post that you have a script that you refer to as a bot. I wouldn't know how to alter that script unless I could see it.
Title: Re: Top posters
Post by: nitishthelegendkiller on April 16, 2008, 07:09:21 AM
No, several other posters like 5-6 normal members doesn't want to participate.Its ok to me but they just don't want their names in the list, as its a post based so they also cannot do about it.So, i was looking for some script so that this script ignores few users if i type in their ids, or id no. or something...
Title: Re: Top posters
Post by: JPDeni on April 16, 2008, 02:47:37 PM
I really got it wrong, didn't I? :)

You can add a line to the query.

Before


ORDER BY m.posts DESC


you can add


AND m.ID_MEMBER NOT IN (34,87,156)


substituting the numbers of the people you want to exclude.
Title: Re: Top posters
Post by: darkwind on April 18, 2008, 04:47:48 AM
Quote from: JPDeni on October 19, 2006, 01:58:12 AM
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.

Hi,

Great piece of code!

I got this to work and modified it a little so that it shows the rank(top poster is #1) of the poster. What i wanted to know is how can I add th user's avatar with a set width and height, say, 20px x 20px.

Help will be very much appreciated.

Thanks in advance.

darkwind
Title: Re: Top posters
Post by: JPDeni on April 18, 2008, 12:53:03 PM
I don't know. I've never figured out how to work with avatars.

And please don't change the font size in your posts. Some of us have been around a few more years than others and our eyes aren't as good as they used to be. I had to copy your text and paste it into a text editor in order to be able to read it.
Title: Re: Top posters
Post by: darkwind on April 18, 2008, 01:37:51 PM
ok. noted. my apologies.

hope someone will be able to shed some light.

thanks.
Title: Re: Top posters
Post by: Lord Anubis on April 18, 2008, 08:08:14 PM
I got it working with the avatar, using this code


global $db_prefix, $scripturl, $memberContext, $txt, $modSettings, $context, $settings, $options;

$starttime = strtotime('24 hours ago');
$list_count = 10;

$poster = array();

$request = db_query("
SELECT  m.ID_MEMBER, COUNT(m.ID_MEMBER) as postCount
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b)
WHERE m.posterTime > " . $starttime . "
AND t.ID_TOPIC = m.ID_TOPIC
AND b.ID_BOARD = t.ID_BOARD" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? " AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
GROUP BY m.ID_MEMBER
ORDER BY postCount DESC LIMIT " . $list_count, __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($request))
{
    loadMemberData(array($row['ID_MEMBER']));
    loadMemberContext($row['ID_MEMBER']);
$poster[$row['ID_MEMBER']] = array (
  'id' => $row['ID_MEMBER'],
  'count' => $row['postCount'],
   'ava' =>$memberContext[$row['ID_MEMBER']]['avatar']['image'],
  'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '" title="' . $txt[92] . ' ' . $memberContext[$row['ID_MEMBER']]['name'] . '">' . '<font color="' . $memberContext[$row['ID_MEMBER']]['group_color'] . '">' . $memberContext[$row['ID_MEMBER']]['name'] . '</font>' . '</a>' );
}
mysql_free_result($request);

echo '<table width=100%>';
foreach($poster as $top_user)
{
echo '<tr>
      <td align="left" width=10%>' . $top_user['ava'] .  '</td>
      <td align="left" width=80%>' . $top_user['link'] . '</td>
      <td align="right"> '. $top_user['count'] . '</td>
      </tr>';
}
echo '</table>';


The only problem is the avatars need to be resized

here is a screenshot of what I have so far:
(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fnextsite.org%2Fforum%2Fimagehost%2Fuploads%2F1eacbb031a.jpg&hash=35d12e76da522449d764a9571622510e2de3530e)
Title: Re: Top posters
Post by: IchBin on April 18, 2008, 09:03:09 PM
You won't be able to "resize" theme without using some php library like GD. You could limit the HTML to only display a certain size, but that would be cutting the avatar off, and not "resizing" it.
Title: Re: Top posters
Post by: Lord Anubis on April 18, 2008, 10:37:41 PM
Couldn't a function like this be applied?


'ava' => ‘<img src="', htmlspecialchars($memberContext[$row['ID_MEMBER']]['avatar']['image']), '" width="20" alt="">’,


This one is giving a parse error, but I was wondering if this would be on the right track to getting this to work
Title: Re: Top posters
Post by: JPDeni on April 18, 2008, 10:46:00 PM
That'll work, but you might end up with distorted avatars. If the original is wider than 20 pixels, then the avatar will look tall and skinny. If the original is narrower than 20 pixels, the avatar will look short and fat. It might not make a whole lot of difference, but it'll be noticeable, especially to the owners of the avatars.

I think your parse error is because you've ended the line with a , instead of a ;
Title: Re: Top posters
Post by: Lord Anubis on April 18, 2008, 10:57:37 PM
Hmmm...I tried changing the comma to a semicolon and still recieved a parse error here is the code thus far


global $db_prefix, $scripturl, $memberContext, $txt, $modSettings, $context, $settings, $options;

$starttime = strtotime('24 hours ago');
$list_count = 10;

$poster = array();

$request = db_query("
SELECT  m.ID_MEMBER, COUNT(m.ID_MEMBER) as postCount
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b)
WHERE m.posterTime > " . $starttime . "
AND t.ID_TOPIC = m.ID_TOPIC
AND b.ID_BOARD = t.ID_BOARD" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? " AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
GROUP BY m.ID_MEMBER
ORDER BY postCount DESC LIMIT " . $list_count, __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($request))
{
    loadMemberData(array($row['ID_MEMBER']));
    loadMemberContext($row['ID_MEMBER']);

$poster[$row['ID_MEMBER']] = array (
  'id' => $row['ID_MEMBER'],
  'count' => $row['postCount'],
   'ava' => '<img src="', htmlspecialchars($memberContext[$row['ID_MEMBER']]['avatar']['image']), '" width="20" alt="">';
  'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '" title="' . $txt[92] . ' ' . $memberContext[$row['ID_MEMBER']]['name'] . '">' . '<font color="' . $memberContext[$row['ID_MEMBER']]['group_color'] . '">' . $memberContext[$row['ID_MEMBER']]['name'] . '</font>' . '</a>' );
}
mysql_free_result($request);

echo '<table width=100%>';
foreach($poster as $top_user)
{
echo '<tr>
      <td align="left" width="20"> '. $top_user['ava'] .'</td>
      <td align="left" width=50%>' . $top_user['link'] . '</td>
      <td align="right"> '. $top_user['count'] . '</td>
      </tr>';
}
echo '</table>';


I have been looking through it and haven't seen anything that looks outta the ordinary that would make it parse...

Now I am stumped  :uglystupid2:
Title: Re: Top posters
Post by: JPDeni on April 18, 2008, 11:02:33 PM
What exactly is your parse error? It makes it a whole lot easier to find things if I know what I'm looking for.
Title: Re: Top posters
Post by: Lord Anubis on April 18, 2008, 11:46:26 PM
Thats what I usually use, but in TP 1.05 it doesn't tell you which line...The block just doesn't show up
Title: Re: Top posters
Post by: darkwind on April 19, 2008, 01:24:36 AM
Thanks for the code, one thing I would like is to not put a start time but to take the top posters all-time.

I know what line it is I'm just not sure what value should it be.

$starttime = strtotime('24 hours ago');
Title: Re: Top posters
Post by: JPDeni on April 19, 2008, 01:48:19 AM
darkwind:
Quote
I know what line it is I'm just not sure what value should it be.


$starttime = 0;


Anubis, I just got home. I'll take a look at your code if I can find it. I have received parse code line numbers when there was a problem, so it probably is more of a logic error than a parse code error. But I'll take a look.
Title: Re: Top posters
Post by: Lord Anubis on April 19, 2008, 01:53:01 AM
Thanks JP :)
Title: Re: Top posters
Post by: JPDeni on April 19, 2008, 02:12:29 AM
You were right about ending that line with a comma. I didn't realize it was part of an array.

I'm getting a return. At first I didn't think I was, but then I realized there were no posts in the past 24 hours, so it's logical that nothing would be there. But when I added it to my live active site, I got the list of today's posters. Are you sure you have posts within the time frame that you've set?
Title: Re: Top posters
Post by: Lord Anubis on April 19, 2008, 02:16:09 AM
Yes tons my site is very active :)

and the code keeps up with the users postings correctly as I have observed (without the use of the avatars)
Title: Re: Top posters
Post by: Lord Anubis on April 19, 2008, 02:26:50 AM
Update okay I reinserted the code into a new Block, then turned off my other old one and I am getting a return but no avatars are showing
Title: Re: Top posters
Post by: darkwind on April 19, 2008, 02:33:13 AM
Quote from: darkwind on April 19, 2008, 01:24:36 AM
Thanks for the code, one thing I would like is to not put a start time but to take the top posters all-time.

I know what line it is I'm just not sure what value should it be.

$starttime = strtotime('24 hours ago');

Got it to work. Thanks everyone!
Title: Re: Top posters
Post by: JPDeni on April 19, 2008, 02:40:45 AM
Glad you got it sorted, darkwind.

I don't know what the issue is, Anubis. I haven't worked with avatars enough to be able to get them to work for me either.
Title: Re: Top posters
Post by: Lord Anubis on April 19, 2008, 02:44:15 AM
Well I will keep trying to see if I can get this last piece of the puzzle sorted

Thanks for your help  :up:

I did a check using Internet Explorer to see where it is trying to get the image from and it spit out some funky looking url, LOL

http://www.mysite.com/forum/%3C/td%3E%20%20%20%20%20%20%3Ctd%20align=
Title: Re: Top posters
Post by: darkwind on April 20, 2008, 03:36:54 PM
Hi!

I'm back


$request = db_query("
SELECT  m.ID_MEMBER, COUNT(m.ID_MEMBER) as postCount
FROM ({$db_prefix}messages AS m, {$db_prefix}topics AS t, {$db_prefix}boards AS b)
WHERE m.posterTime > " . $starttime . "
AND t.ID_TOPIC = m.ID_TOPIC
AND b.ID_BOARD = t.ID_BOARD" . (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? " AND b.ID_BOARD != $modSettings[recycle_board]" : '') . "
GROUP BY m.ID_MEMBER
ORDER BY postCount DESC LIMIT " . $list_count, __FILE__, __LINE__);


I would like to change the query above so that it will only select posts from a particular board.

Any help will be much appreciated.

Thanks in advance
darkwind
Title: Re: Top posters
Post by: JPDeni on April 20, 2008, 04:04:37 PM
Put this with the other "AND" commands -- somewhere between the "WHERE" line and the "GROUP BY" line


AND b.ID_BOARD = 43


Change the 43 to the number of the board you want to use.
Title: Re: Top posters
Post by: darkwind on April 20, 2008, 04:21:22 PM
That was quick and works perfectly.

Thanks!
Title: Re: Top posters
Post by: owvvwo on May 06, 2008, 05:46:08 AM
hello iam use the following code topposter

global $db_prefix, $scripturl, $modSettings;

$memberstoshow = 7;
$matchperiod = true;
$countmodsandadmins = true; // not yet implemented
// Change this to the time you want the contest to start [http://www.onlineconversion.com/unix_time.htm]
$starttime = time() - 604800; // Last week posters
$endtime = time();  // Change this to the time you want the contest to end
$where_period = '';

if (!empty($modSettings['MemberColorLink'])) // check if MemberColorLink mod is installed and enabled         
{
    if ($matchperiod) // select only posts matching period
        $where_period = "AND m.posterTime > $starttime AND m.posterTime < $endtime";
    $query = db_query(
        "SELECT m.realName, m.ID_GROUP, m.ID_MEMBER, mg.onlineColor, m.posts
         FROM {$db_prefix}members AS m
         LEFT JOIN {$db_prefix}membergroups AS mg ON (m.ID_GROUP = mg.ID_GROUP AND m.ID_GROUP)
         $where_period
         ORDER BY m.posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}
else
{
    if ($matchperiod) // select only posts matching period
        $where_period = "WHERE posterTime > $starttime AND posterTime < $endtime";
    $query = db_query(
        "SELECT realName, ID_GROUP, ID_MEMBER, posts
         FROM {$db_prefix}members
         $where_period
         ORDER BY posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}

$firstrecord = true;
if($countmodsandadmins)
{
while ($row = mysql_fetch_assoc($query))
{

if ($firstrecord)
    {
        $biggest = $row['posts'];
        $firstrecord = false;
    }
    $bar_length = intval(($row['posts']/$biggest) * 40);

    if(isset($row['onlineColor']))
        $style = 'color: '. $row['onlineColor'];
    else
        $style = '';

    echo '
    <table width="100%" border="0">
    <tr>
    <td><div class="smalltext"><b><a style="' . $style . '" href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a></b> (' . $row['posts'] . ')</div></td>
    <td><div align="right"><img src="' . $settings['images_url'] . '/bar.gif" width="' . $bar_length . '" height="10" title="' . $bar_length*2.5 . '%" alt="" /></div></td>
    </tr>
    </table>';
}
}

else
{
while ($row = mysql_fetch_assoc($query))
{
// Change the ID_GROUP 1 and 2 here to match the groups you don't want in the output
if ($row['ID_GROUP'] != 1 && $row['ID_GROUP'] != 2)
{
if ($firstrecord)
    {
        $biggest = $row['posts'];
        $firstrecord = false;
    }
    $bar_length = intval(($row['posts']/$biggest) * 40);

    if(isset($row['onlineColor']))
        $style = 'color: '. $row['onlineColor'];
    else
        $style = '';

    echo '
    <table width="100%" border="0">
    <tr>
    <td><div class="smalltext"><b><a style="' . $style . '" href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a></b> (' . $row['posts'] . ')</div></td>
    <td><div align="right"><img src="' . $settings['images_url'] . '/bar.gif" width="' . $bar_length . '" height="10" title="' . $bar_length*2.5 . '%" alt="" /></div></td>
    </tr>
    </table>';
    }
}
}



the problem is
if the
$matchperiod = false; 
working fine


but
$matchperiod = true;
this made error


error message:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND m.posterTime > 1209443662 AND m.posterTime < 1210048462
ORDER BY p' at line 3
File: /home/prankcom/public_html/******/Sources/Load.php(1738) : eval()'d code(209) : eval()'d code
Line: 33




help me............
Title: Re: Top posters
Post by: JPDeni on May 06, 2008, 02:38:03 PM
I don't know if this will solve your problem, but I see an error.

Change


if (!empty($modSettings['MemberColorLink'])) // check if MemberColorLink mod is installed and enabled         
{
    if ($matchperiod)  // select only posts matching period
  {
        $where_period = "AND m.posterTime > $starttime AND m.posterTime < $endtime";
    $query = db_query(
        "SELECT m.realName, m.ID_GROUP, m.ID_MEMBER, mg.onlineColor, m.posts
         FROM {$db_prefix}members AS m
         LEFT JOIN {$db_prefix}membergroups AS mg ON (m.ID_GROUP = mg.ID_GROUP AND m.ID_GROUP)
         $where_period
         ORDER BY m.posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}


to


if (!empty($modSettings['MemberColorLink'])) // check if MemberColorLink mod is installed and enabled         
{
    if ($matchperiod)  // select only posts matching period
  {
        $where_period = "WHERE m.posterTime > $starttime AND m.posterTime < $endtime";
    $query = db_query(
        "SELECT m.realName, m.ID_GROUP, m.ID_MEMBER, mg.onlineColor, m.posts
         FROM {$db_prefix}members AS m
         LEFT JOIN {$db_prefix}membergroups AS mg ON (m.ID_GROUP = mg.ID_GROUP AND m.ID_GROUP)
         $where_period
         ORDER BY m.posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}
Title: Re: Top posters
Post by: owvvwo on May 08, 2008, 01:26:47 PM
sorry to disturb you one more time

but i've problem with the following code (red color code)
if i remove working fine
what can i do ?

Quoteglobal $db_prefix, $scripturl, $modSettings;

$memberstoshow = 7;
$matchperiod = true;
$countmodsandadmins = true; // not yet implemented
// Change this to the time you want the contest to start [http://www.onlineconversion.com/unix_time.htm]
$starttime = time() - 604800; // Last week posters
$endtime = time();  // Change this to the time you want the contest to end
$where_period = '';

if (!empty($modSettings['MemberColorLink'])) // check if MemberColorLink mod is installed and enabled         
{
    if ($matchperiod) // select only posts matching period
        $where_period = "AND m.posterTime > $starttime AND m.posterTime < $endtime";
    $query = db_query(
        "SELECT m.realName, m.ID_GROUP, m.ID_MEMBER, mg.onlineColor, m.posts
         FROM {$db_prefix}members AS m
         LEFT JOIN {$db_prefix}membergroups AS mg ON (m.ID_GROUP = mg.ID_GROUP AND m.ID_GROUP)
         $where_period
         ORDER BY m.posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}
else
{
    if ($matchperiod) // select only posts matching period
        $where_period = "WHERE posterTime > $starttime AND posterTime < $endtime";
    $query = db_query(
        "SELECT realName, ID_GROUP, ID_MEMBER, posts
         FROM {$db_prefix}members
         $where_period
         ORDER BY posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
}

$firstrecord = true;
if($countmodsandadmins)
{
while ($row = mysql_fetch_assoc($query))
{

      if ($firstrecord)
       {
           $biggest = $row['posts'];
           $firstrecord = false;
       }
       $bar_length = intval(($row['posts']/$biggest) * 40);

       if(isset($row['onlineColor']))
           $style = 'color: '. $row['onlineColor'];
       else
           $style = '';
   
       echo '
          <table width="100%" border="0">
             <tr>
                <td><div class="smalltext"><a style="' . $style . '" href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a> (' . $row['posts'] . ')</div></td>
                <td><div align="right"><img src="' . $settings['images_url'] . '/bar.gif" width="' . $bar_length . '" height="10" title="' . $bar_length*2.5 . '%" alt="" /></div></td>
             </tr>
          </table>';
}
}

else
{
while ($row = mysql_fetch_assoc($query))
{
// Change the ID_GROUP 1 and 2 here to match the groups you don't want in the output
   if ($row['ID_GROUP'] != 1 && $row['ID_GROUP'] != 2)
   {
      if ($firstrecord)
       {
           $biggest = $row['posts'];
           $firstrecord = false;
       }
       $bar_length = intval(($row['posts']/$biggest) * 40);

       if(isset($row['onlineColor']))
           $style = 'color: '. $row['onlineColor'];
       else
           $style = '';
   
       echo '
          <table width="100%" border="0">
             <tr>
                <td><div class="smalltext"><a style="' . $style . '" href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a> (' . $row['posts'] . ')</div></td>
                <td><div align="right"><img src="' . $settings['images_url'] . '/bar.gif" width="' . $bar_length . '" height="10" title="' . $bar_length*2.5 . '%" alt="" /></div></td>
             </tr>
          </table>';
    }
}
}
Title: Re: Top posters
Post by: JPDeni on May 08, 2008, 01:32:34 PM
If you remove it, you won't get posts within the time frame.

Try this.

Replace


    if ($matchperiod) // select only posts matching period
        $where_period = "WHERE posterTime > $starttime AND posterTime < $endtime";
    $query = db_query(
        "SELECT realName, ID_GROUP, ID_MEMBER, posts
         FROM {$db_prefix}members
         $where_period
         ORDER BY posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);


with


    $query = db_query(
        "SELECT realName, ID_GROUP, ID_MEMBER, posts
         FROM {$db_prefix}members
         WHERE posterTime > $starttime AND posterTime < $endtime
         ORDER BY posts DESC
         LIMIT 0,$memberstoshow", __FILE__, __LINE__);
Title: Re: Top posters
Post by: confuzed on June 11, 2008, 02:35:23 PM
Is it possible to adapt this a little bit for a post contest so that the total number of forum posts is also displayed plus what your target number of posts is, with a countdown to say how many are still needed?

Like this:

Posting target  250,000 posts
Current forum posts 200,000 posts
Number of posts needed to reach target : 50,000

So that the current forum posts and the number needed to reach target would change every time someone posts

and then underneath you could have the top ten posters post counts for the period.

Title: Re: Top posters
Post by: jdvarner on November 01, 2008, 03:51:08 PM
Im using this code for the top posts block for this month. I want to make it where it ignores the posts of just one specific board. Is there a line of code i can add so it ignores this one specific board.

Thanks.

global $db_prefix, $scripturl;

$starttime = 1225551600; // Change this to the time you want the contest to start
$endtime = 1228089599;  // 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
     
     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 > 10) 
    break;
}
Title: Re: Top posters
Post by: JPDeni on November 01, 2008, 04:22:37 PM

     ON {$db_prefix}members.ID_MEMBER = {$db_prefix}messages.ID_MEMBER
     WHERE ID_BOARD <> XX
     AND posterTime > $starttime
     AND posterTime < $endtime", __FILE__, __LINE__);


Replace the XX with the number of the board you want to exclude.
Title: Re: Top posters
Post by: jdvarner on November 02, 2008, 03:50:18 AM
Thank you JP. That worked great. Thank You.
Title: Re: Top posters
Post by: confuzed on February 14, 2009, 12:08:43 PM
Quote from: JPDeni on November 01, 2008, 04:22:37 PM

     ON {$db_prefix}members.ID_MEMBER = {$db_prefix}messages.ID_MEMBER
     WHERE ID_BOARD <> XX
     AND posterTime > $starttime
     AND posterTime < $endtime", __FILE__, __LINE__);


Replace the XX with the number of the board you want to exclude.


ooh is it possible to do this in reverse, and specify the boards you want to include?  As this would be great if it only included certain on-topic boards :)

thanks in advance
Title: Re: Top posters
Post by: JPDeni on February 15, 2009, 01:11:09 PM
Sure.


WHERE ID_BOARD = #
OR ID_BOARD = #


Fill in the boards you want instead of the # character. Add as many OR lines as you need.
Title: Re: Top posters
Post by: confuzed on February 15, 2009, 02:23:28 PM
thanks JPdeni

and with this one excluding boards can I do the same thing and just add as many

of these  lines as boards that I want to exclude?

WHERE ID_BOARD <> XX


Quote from: JPDeni on November 01, 2008, 04:22:37 PM

     ON {$db_prefix}members.ID_MEMBER = {$db_prefix}messages.ID_MEMBER
     WHERE ID_BOARD <> XX
     AND posterTime > $starttime
     AND posterTime < $endtime", __FILE__, __LINE__);


Replace the XX with the number of the board you want to exclude.

My problem is that I want to exclude the off-topic boards, but I think I have more on-topic boards, so I'm trying to work out the easiest/quickest way to only count the boards I want.  I thought entering each on-topic board would work but there are probably more of them than off-topic, and they also get added too, whereas the off-topic boards are static and there are probably slightly less of them.

Is it possible to use this then

WHERE ID_BOARD <> XX

one line for each off-topic board I want to exclude?  Or do they have to be added like in a list (array?)

thanks again for your help
Title: Re: Top posters
Post by: JPDeni on February 16, 2009, 04:36:52 AM
If you want an answer today, the answer is:

to include boards, use a series of OR statements as above. You can have as many as you want, but the first one must be a WHERE and after that, each one is an OR.

or

to exclude boards, use a series of AND statements.


WHERE ID_BOARD <> #
AND ID_BOARD <> #
AND ID_BOARD <> #


Again, use as many as you want. The first one starts with WHERE and after that, each one starts with AND.

There is probably a more elegant way to do this, but I've been up for far too long and I can't think of what it is right now.
Title: Re: Top posters
Post by: Paragaya on February 22, 2009, 09:16:31 AM
Thanks I think

$top_posters = ssi_topPoster(5, 'array');

echo '
<ol>';

foreach ($top_posters as $poster)
echo '
<li>', $poster['link'], ' - ', $poster['posts'], '</li>';

echo '
</ol>';


Title: Re: Top posters
Post by: fangweile on March 01, 2009, 11:56:42 AM
hello there,

I am looking for top 10 poster that will display similar to this format.

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fimg511.imageshack.us%2Fimg511%2F5723%2Ftop10fa6.jpg&hash=2a16a42aee121dcf5543950947869d4846c29bcc)

Any idea how to achieve it.

Thanks in advance  ;)
Title: Re: Top posters
Post by: JPDeni on March 01, 2009, 01:34:23 PM
This is overall top posters or only those from certain boards? Where is the "rank" definied?
Title: Re: Top posters
Post by: fangweile on March 02, 2009, 01:48:16 AM
Yeah, this is the overall forum top poster. Rank is defined as membergroup name.
Title: Re: Top posters
Post by: JPDeni on March 02, 2009, 04:52:12 AM
I'm sorry. I can't figure out what they do with the stars. Makes no sense to me. Maybe if I look at it later I'll understand it. Or maybe someone else will be able to help.
Title: Re: Top posters
Post by: Lord Anubis on March 02, 2009, 05:30:12 AM
JPDeni...

just to clarify what the coding is, I can't figure out how to do it either lol, but it would be pretty cool  :up:

It would show as follows:

1. a number in front of the user name followed by the number of posts this user has
2. underneath this data the membergroup this user belongs to for instance...if it were your data and ATM you were the top poster on TP it would look like:


1.  JPDeni (3249)
(https://www.tinyportal.net/Themes/bz29/images/tp-code.gif)

2.  Lord Anubis (653)
(https://www.tinyportal.net/Themes/bz29/images/star.gif)(https://www.tinyportal.net/Themes/bz29/images/star.gif)(https://www.tinyportal.net/Themes/bz29/images/star.gif)(https://www.tinyportal.net/Themes/bz29/images/star.gif)(https://www.tinyportal.net/Themes/bz29/images/star.gif)

etc.....


Does that help at all? 


EDIT: Aha...see where a problem in coding this might lye is because if using stars, rather than full images it uses a function to check the number of postings and adds an image to it....dunno the difficulties that might impose


Hope I make any sense :)
Title: Re: Top posters
Post by: ZarPrime on March 02, 2009, 07:28:47 AM
JPDeni,

These stars are obviously for the post count based groups, not for regular membergoups.  The difference is that she is using 5 yellow stars for Captain and 5 red stars for Colonel.  See enclosed images.

ZarPrime
Title: Re: Top posters
Post by: JPDeni on March 02, 2009, 04:10:22 PM
I know all that, guys. :) I looked at the code which displays the stars and I can't figure out what the code means. IIRC, it's in Load.php in either loadMemberContext or loadMemberData. Theoretically, I could probably just run those functions, but it seems such a waste of resources to get all that data when all I need is the stars. The problem I have is in breaking down the code for the stars to figure out how they got it.