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

Recent

Welcome to TinyPortal. Please login or sign up.

March 28, 2024, 08:16:08 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,104
  • Total Topics: 21,212
  • Online today: 151
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 1
  • Guests: 153
  • Total: 154
  • tino

[Block] Top 10 Karma

Started by Paragaya, March 01, 2009, 08:50:45 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Paragaya

Add new php blok :)



SMF 1.1:

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:

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

kfrost

#1
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">';

JPDeni

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


<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

#3
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

kfrost

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

I remember having problems like that before, so I searched out the code I wrote for it. This seems to work:


SELECT realName, (karmaGood - karmaBad) as Karma, ID_MEMBER,


You need the parentheses.

kfrost

#6
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?


saks

How show total karma for current logged user ?