PHP Gesior - Ranking Frags BUG

secondlife

Member
Joined
Aug 1, 2009
Messages
260
Best answers
0
Reaction score
20
Hi people,

I tried to adapt this Ranking Storage by @imkingran in my project:
AAC - Gesior topfraggers by storage

But i do not want to use by storage. I would like to use only by values contained in table players -> column 'frags'.

Resuming, I'm trying to create a Ranking Kills using a single column.

At this moment, my code is:
Code:
<?php
$main_content .= '<div style="text-align: center; font-weight: bold;">Top 30 fraggers on ' . htmlspecialchars($config['server']['serverName']) . '</div>
<table border="0" cellspacing="1" cellpadding="4" width="100%">
  <tr bgcolor="' . $config['site']['vdarkborder'] . '">
      <td class="white" style="text-align: center; font-weight: bold;">Top</td>
      <td class="white" style="text-align: center; font-weight: bold;">Name</td>
      <td class="white" style="text-align: center; font-weight: bold;">Frags</td>
  </tr>';
  
$i = 0;
foreach($SQL->query("SELECT `frags` FROM `players` WHERE `world_id` = 0 AND `frags` > 0 ORDER BY `frags` DESC LIMIT 30") as $player)
{
    $i++;
    $pName = $SQL->query('SELECT '.$SQL->fieldName('name').' FROM '.$SQL->tableName('players').' WHERE '.$SQL->fieldName('frags').' > 0')->fetch();
    $main_content .= '<tr bgcolor="' . (is_int($i / 2) ? $config['site']['lightborder'] : $config['site']['darkborder']) . '">
      <td style="text-align: center"> '.$i.'.</td>
      <td><a href="?subtopic=characters&name=' . urlencode($pName['name']) . '">' . htmlspecialchars($pName['name']) . '</a></td>
      <td style="text-align: center;">' .$player['frags'].'</td>
  </tr>';
}
$main_content .= '</table>';
?>
The code not works 100% correctly, frag count is OK, but the players names are repeating.

Any idea to fix it? I think the problem is in line:
Code:
$pName = $SQL->query('SELECT '.$SQL->fieldName('name').' FROM '.$SQL->tableName('players').' WHERE '.$SQL->fieldName('frags').' > 0')->fetch();
but i have no idea how to solve it, i tried many times.

If anyone can help me, I will be very grateful.
Thank you!
 
Last edited:

slawkens

Developer
Premium User
Joined
Aug 27, 2007
Messages
2,890
Best answers
64
Reaction score
400
Location
Germany
Yes, you are right - this query is wrong:
Code:
$pName = $SQL->query('SELECT '.$SQL->fieldName('name').' FROM '.$SQL->tableName('players').' WHERE '.$SQL->fieldName('frags').' > 0')->fetch();
You are selecting ALWAYS the same list of players that got more than 0 frags. The list has more than 1 player, but it always returns the first one found.

Solution?
So, what you need to do, is to modify this query:
Code:
foreach($SQL->query("SELECT `frags` FROM `players` WHERE `world_id` = 0 AND `frags` > 0 ORDER BY `frags` DESC LIMIT 30") as $player)
To select players.name. It will be just all in one query, not two.

Like this:
Code:
foreach($SQL->query("SELECT `name`, `frags` FROM `players` WHERE `world_id` = 0 AND `frags` > 0 ORDER BY `frags` DESC LIMIT 30") as $player)
Then in your code use:
Code:
$player['name']
TIP: The other query (first one in this post) you can remove, it's useless.
 
Top