TinyPortal

Development => Block Codes => Topic started by: darkangel on February 07, 2014, 09:09:10 AM

Title: Top Posters
Post by: darkangel on February 07, 2014, 09:09:10 AM
You all gave me this code eons ago...we luvs it a lot too but is there anyway to have it ignore---not show the admins in the list?



global $smcFunc, $scripturl, $modSettings, $context;

// Number of top posters displayed
$topPoster = 45;

// Find the latest poster.
$request = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.show_online, mem.real_name, mem.posts, a.id_attach, a.attachment_type, a.filename
FROM ({db_prefix}members as mem)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
WHERE ' .($context['user']['is_admin'] ? '1' : 'show_online = 1') . '
ORDER BY posts DESC
LIMIT {int:limit}',
array('limit' => $topPoster)
);

$users = array();

while ($row = $smcFunc['db_fetch_assoc']($request))
{
$users[] = array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
'posts' => $row['posts'],
'show' => $row['show_online'],

);
}

$smcFunc['db_free_result']($request);

// Output our array of users with avatar, posts, and name
echo '
<table cellpadding="0" cellspacing="10">';

foreach ($users as $user)
{
echo '
<tr>

<td><h5 style="margin: 4px,0,0,4px;">'.$user['link'].'</h5></td><td><h5 style="margin: 4px,0,0,4px;">'. $user['posts'] .'</h5></td>
</tr>';
}

echo '
</table>';


Title: Re: Top Posters
Post by: IchBin on February 08, 2014, 11:09:02 PM
You can add a check in like this right after the foreach loop.

foreach ($users as $user)
{
    if ($user['id'] = 1)
        continiue;

   
If you need to check for multiple admins you can use an array.

foreach ($users as $user)
{
            $admins = array(1,3,4);
    if (in_array($user['id'], $admins))
        continiue;

Title: Re: Top Posters
Post by: darkangel on February 08, 2014, 11:47:28 PM
so the 1, 3, 4 should it be the actual admin id # --- like our admins are 1,2,3,4

with a token one that never gets used anymo...LOL
Title: Re: Top Posters
Post by: darkangel on February 09, 2014, 02:47:44 AM
 :(

Admins still show in list, this is how I did it. Did I do it right?






foreach ($users as $user)
{
$admins = array(1,2,3,4);
    if (in_array($user['id'], $admins))
       
continue;
echo'
Title: Re: Top Posters
Post by: IchBin on February 09, 2014, 03:40:14 AM
Assuming that 1,2,3,4 are the ID numbers for your admin accounts?
Title: Re: Top Posters
Post by: darkangel on February 09, 2014, 04:01:30 AM
yes when I set up the site I set them up in order as well
Title: Re: Top Posters
Post by: IchBin on February 09, 2014, 04:10:48 AM
Well I just tried this code and it worked fine:


global $smcFunc, $scripturl, $modSettings, $context;

// Number of top posters displayed
$topPoster = 45;

// Find the latest poster.
$request = $smcFunc['db_query']('', '
SELECT mem.id_member, mem.show_online, mem.real_name, mem.posts, a.id_attach, a.attachment_type, a.filename
FROM ({db_prefix}members as mem)
LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = mem.id_member)
WHERE ' .($context['user']['is_admin'] ? '1' : 'show_online = 1') . '
ORDER BY posts DESC
LIMIT {int:limit}',
array('limit' => $topPoster)
);

$users = array();

while ($row = $smcFunc['db_fetch_assoc']($request))
{
$users[] = array(
'id' => $row['id_member'],
'name' => $row['real_name'],
'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
'posts' => $row['posts'],
'show' => $row['show_online'],

);
}

$smcFunc['db_free_result']($request);

// Output our array of users with avatar, posts, and name
echo '
<table cellpadding="0" cellspacing="10">';

foreach ($users as $user)
{
$admins = array(1,2);
if (in_array($user['id'], $admins))
continue;
echo '
<tr>

<td><h5 style="margin: 4px,0,0,4px;">'.$user['link'].'</h5></td><td><h5 style="margin: 4px,0,0,4px;">'. $user['posts'] .'</h5></td>
</tr>';
}

echo '
</table>';
Title: Re: Top Posters
Post by: darkangel on February 09, 2014, 04:58:12 AM
As with everything else I hae done today---including a tossing a folder containing info about our contest for Dec 2013 and Jan -now of winner info and emptying trash bin--what will go right mebbe?

I copy pasted your code you tried....and went to my forum/deleted all from box/saved
then entered your code adding the other 2 admins and they are now gone from list. this sure beats going into the accounts and resetting us to 0, since it is to motivate the members to write more posts...LOL

Thanks for your patience with this dolt. It now works. O0