Welcome, Guest. Please login or register.
Did you miss your activation email?
September 02, 2014, 05:41:03 PM

Login with username, password and session length

Last 25 Topics



Note:  Clicking the link above will open a new tab in your browser !!

Recent

Members
  • Total Members: 3449
  • Latest: jkrlvgn
Stats
  • Total Posts: 173908
  • Total Topics: 19845
  • Online Today: 83
  • Online Ever: 278
  • (October 31, 2012, 08:52:18 AM)
Users Online
Users: 0
Guests: 47
Total: 47

Donate

Help us to keep the support site
going, Please consider a small donation.

Thank you
Please read the Posting Guidelines

Author Topic: [Block] Top 10 Karma  (Read 11482 times)

0 Members and 1 Guest are viewing this topic.

Paragaya

  • Guest
[Block] Top 10 Karma
« on: March 01, 2009, 01:50:45 AM »
Add new php blok :)



SMF 1.1:

Code: [Select]
global $db_prefix, $scripturl;

$members_result = db_query("
SELECT ID_MEMBER, realName, karmaGood
FROM {$db_prefix}members
ORDER BY karmaGood DESC
LIMIT 10", __FILE__, __LINE__);
$members = array();
while ($row_members = mysql_fetch_assoc($members_result))
{
$members[] = array(
'name' => $row_members['realName'],
'id' => $row_members['ID_MEMBER'],
'karma' => $row_members['karmaGood'],
'href' => $scripturl . '?action=profile;u=' . $row_members['ID_MEMBER'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['ID_MEMBER'] . '">' . $row_members['realName'] . '</a>'
);
}
mysql_free_result($members_result);

if (empty($members))
return;

echo '
<ul style="padding: 0 0 0 2em;">';

foreach ($members as $member)
echo '
<li>', $member['link'], ' - ', $member['karma'], '</li>';

echo '
</ul>';

SMF 2.0:

Code: [Select]
global $smcFunc, $scripturl;

$members_result = $smcFunc['db_query']('', '
SELECT id_member, real_name, karma_good
FROM {db_prefix}members
ORDER BY karma_good DESC
LIMIT 10');
$members = array();
while ($row_members = $smcFunc['db_fetch_assoc']($members_result))
{
$members[] = array(
'name' => $row_members['real_name'],
'id' => $row_members['id_member'],
'karma' => $row_members['karma_good'],
'href' => $scripturl . '?action=profile;u=' . $row_members['id_member'],
'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_members['id_member'] . '">' . $row_members['real_name'] . '</a>'
);
}
$smcFunc['db_free_result']($members_result);

if (empty($members))
return;

echo '
<ul class="normallist">';

foreach ($members as $member)
echo '
<li>', $member['link'], ' - ', $member['karma'], '</li>';

echo '
</ul>';

Thanks Paragaya Yağız... , Blue Dream
« Last Edit: March 02, 2009, 05:28:47 AM by Paragaya »

kfrost

  • Guest
Re: [Block] Top 10 Karma
« Reply #1 on: May 14, 2009, 04:50:55 PM »
Paragaya,

Thank you so much, I've been thinking about something like this.  Question, I added this to our forum, SMF 1.18, TP 1.03, you can view the at www.berewickforums.com, the bullet items are centered justified, and I'd like to get them left justified.  If you take a look at the link above you should see how the existing justification causes some items to take up 2 lines.

I'm a developer but with zero PHP experience.  Any help on how to correct this problem would be greatly appreciated.

Doh, actually figured it out myself.  Was going to delete this but in case somebody else runs into this.

To get everything to the left, I did the following.

<ul style="padding: 0 0 0 0; margin: 0 0 0 0">';
« Last Edit: May 14, 2009, 04:56:45 PM by kfrost »

JPDeni

  • Guest
Re: [Block] Top 10 Karma
« Reply #2 on: May 14, 2009, 05:02:56 PM »
It has to do with your style.css file in your theme. When I went to your site, I viewed it with the default theme and the list is left-justified.

You could probably use in-line css if you wanted to, though. Just add it to the <li> tag. Something like

Code: [Select]
<li style="text-align:left;">', $member['link'], ' - ', $member['karma'], '</li>';

You can put anything there, just like you would for a regular html page.

kfrost

  • Guest
Re: [Block] Top 10 Karma
« Reply #3 on: May 14, 2009, 05:06:23 PM »
Thanks JP,

I've got it how I want it now.  There is a problem with this block, it only displays positive Karma points instead of the total between Positive and Negative.

P.S. Maybe I should clarify, it's a problem if your displaying totals.  I assume there should be a way to do a column based on sum and use it.  I'm assumming this is going to be like most T-SQL but if anybody has this I would appreciate it.

I was assumming something such as this would work but apparently not.

SELECT ID_MEMBER, realName, karmaGood - karmaBad as
             karmaTotal
   FROM {$db_prefix}members
   ORDER BY karmaTotal DESC
   LIMIT 10", __FILE__, __LINE__);

Thanks
« Last Edit: May 14, 2009, 05:19:53 PM by kfrost »

kfrost

  • Guest
Re: [Block] Top 10 Karma
« Reply #4 on: May 14, 2009, 05:33:23 PM »
Hmm, if I just use karmaBad, the correct figures show up.  If do a karmaGood + karmaBad as karmaTotal, that seems to work.

However, karmaGood - karmaBad, I'm getting figures such as 18446744073709551615

If you go into Forum Profile Information, there is a total label.  Is this by chance stored in the database, or does anybody know how that's being done to migrate the functionality over to this code block?


JPDeni

  • Guest
Re: [Block] Top 10 Karma
« Reply #5 on: May 14, 2009, 05:53:50 PM »
I remember having problems like that before, so I searched out the code I wrote for it. This seems to work:

Code: [Select]
SELECT realName, (karmaGood - karmaBad) as Karma, ID_MEMBER,

You need the parentheses.

kfrost

  • Guest
Re: [Block] Top 10 Karma
« Reply #6 on: May 14, 2009, 05:58:58 PM »
JP,

First thanks for you help here.  I added the parens as you suggested and still getting the same results.  The problems are with users with say 1 applaud and 5 smites.  It's like it going when it's dropping below zero, instead of going to a negative number, it's looping back at the highest number for an integer or whatever these fields are and counting back down.  Kind of what you might see with an unsigned int?

« Last Edit: May 14, 2009, 06:01:32 PM by kfrost »

Offline saks

  • Full Member
  • ***
  • Posts: 119
    • Paragliding and kiting in Krasnoyarsk
Re: [Block] Top 10 Karma
« Reply #7 on: November 22, 2011, 01:43:03 AM »
How show total karma for current logged user ?