TinyPortal

Development => Block Codes => Topic started by: adirisman on April 25, 2009, 11:41:25 AM

Title: [Block] members with the most "posts per day"?
Post by: adirisman on April 25, 2009, 11:41:25 AM
Hi,

Is there any way to show 10 members with the most "posts per day" in a block?

thanks.
Title: Re: Block: members with the most "posts per day"?
Post by: G6Cad on April 25, 2009, 12:04:28 PM
Did you check the block code and snippets board ?
Title: Re: Block: members with the most "posts per day"?
Post by: JPDeni on April 25, 2009, 07:46:47 PM
I haven't seen anything like that before.

In answer to your question, yes, there is. It would be something like this:


global $db_prefix;
$result = db_query("
SELECT (posts / ( ( UNIX_TIMESTAMP( ) - dateRegistered ) / ( 3600 *24 ) )) AS ppd, realName
FROM {$db_prefix}members
ORDER BY ppd DESC
LIMIT 10", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($result))
echo $row['realName'] . ' ' . $row['ppd'] . '<br />';
mysql_free_result($result);


This would go into a php block.
Title: Re: Block: members with the most "posts per day"?
Post by: adirisman on April 28, 2009, 05:45:29 AM
wow.. thanks...

that works.
Title: Re: [Block] members with the most "posts per day"?
Post by: JPDeni on April 28, 2009, 01:21:05 PM
Cool!  8)

That was a pretty easy one. It was just a matter of looking in the code to see how the posts per day were computed and then putting the same function in the query and letting MySQL do it. I learned something when doing it, too, because I'd never worked with a function in a query before. It opens up a lot of other possibilities.

This was one that was easy to test, too, so it wasn't nearly the problem that I have with other requests. I'm glad I was able to give you something you can use.  :)
Title: Re: [Block] members with the most "posts per day"?
Post by: alhaudhie on April 30, 2009, 05:20:08 PM
how about top poster today.... with the number of posts?
Title: Re: [Block] members with the most "posts per day"?
Post by: JPDeni on April 30, 2009, 05:51:05 PM
When does "today" start? GMT? Server time? Forum time? User's time?

There's just too many possibilities.
Title: Re: [Block] members with the most "posts per day"?
Post by: alhaudhie on April 30, 2009, 06:04:10 PM
oh... tq for reply  :up: :up: ... but i thing a have got it in other topic like

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="left" width=100%>' . $top_user['link'] . '</td>
      <td align="left">| '. $top_user['count'] . '</td>
      </tr>';
}
echo '</table>';
Title: Re: [Block] members with the most "posts per day"?
Post by: JPDeni on April 30, 2009, 06:49:02 PM
That would be server time.

I guess you don't need the code, then, because already found it.
Title: Re: [Block] members with the most "posts per day"?
Post by: Mick on April 30, 2009, 10:47:01 PM
JPDeni,   its crazy how you can whip-up codes in a jiff.

Very cool.  Thanx.
Title: Re: [Block] members with the most "posts per day"?
Post by: chrishicks on May 08, 2009, 11:51:09 AM
I was wondering if someone could tell me why neither of the codes above work for me when I try to apply this as a center block in my memberlist from the custom action.

EDIT: I figured it out. It was turned off(hidden in memberlist) in the settings.

Another question now. I used the second code in this topic and was wondering if someone could tell me how to add horizontal rule to separate the users.
Title: Re: [Block] members with the most "posts per day"?
Post by: JPDeni on May 08, 2009, 01:43:57 PM
The printout on the second code is here:


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


You have two choices. Either you can remove the table formatting and add one hr or you can add two hrs -- one to each table cell. Either way, it's just basic html.


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


or


foreach($poster as $top_user)
{
echo '$top_user['link'] . ' | '. $top_user['count'] . '<hr />';
}
Title: Re: [Block] members with the most "posts per day"?
Post by: WBA Dude on June 14, 2009, 09:19:13 AM
Sorry. Is this added in the html or php blocks?
Title: Re: [Block] members with the most "posts per day"?
Post by: Ken. on June 14, 2009, 01:32:25 PM
Quote from: WBA Dude on June 14, 2009, 09:19:13 AM
Sorry. Is this added in the html or php blocks?

Give it a try both ways to see what works, that way you don't have to wait for an answer. :up:
Title: Re: [Block] members with the most "posts per day"?
Post by: JPDeni on June 14, 2009, 02:28:45 PM
php
Title: Re: [Block] members with the most "posts per day"?
Post by: WBA Dude on June 14, 2009, 04:21:20 PM
thanks
Title: Re: [Block] members with the most "posts per day"?
Post by: JPDeni on June 14, 2009, 07:39:19 PM
Take a look at the code. If it includes echo in it anywhere, it's php code.
Title: Re: [Block] members with the most "posts per day"?
Post by: WBA Dude on June 14, 2009, 07:42:02 PM
Okay. Not as good with php :)

Thanks
Title: Re: [Block] members with the most "posts per day"?
Post by: sandmannd on September 03, 2009, 02:44:29 AM
For some reason I have a hard time getting PHP codes to work. I tride this and it won't work for me. I would love to have this block. Any hints on what I did wrong. I copied and pasted the code into a PHP Code block. Made sure my members were checked and hit save and then activated it. What else would I need to do?

I'm running TinyPortal v1.0 beta 3 Ã,© Bloc   Powered by SMF 1.1.10 | SMF Ã,© 2006-2009, Simple Machines LLC  
Title: Re: [Block] members with the most "posts per day"?
Post by: JPDeni on September 03, 2009, 03:27:52 AM
QuoteAny hints on what I did wrong.

Only if you tell us what "won't work" means. Are you getting an error message? A blank block? No block at all? Strange letters?