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

Recent

Welcome to TinyPortal. Please login or sign up.

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

Top posters

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

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

owvvwo

#140
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>';
    }
}
}

JPDeni

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__);

confuzed

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.


jdvarner

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

JPDeni


     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.

jdvarner

Thank you JP. That worked great. Thank You.

confuzed

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

JPDeni

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.

confuzed

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

JPDeni

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.

This website is proudly hosted on Crocweb Cloud Website Hosting.