• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

PHP Gesior - Ranking Frags BUG

secondlife

Member
Joined
Aug 1, 2009
Messages
298
Reaction score
23
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:
Solution
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...
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.
 
Solution
Back
Top