• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

AAC Fix rank by storage - Missmatching numbers

potinho

Well-Known Member
Joined
Oct 11, 2009
Messages
1,208
Solutions
17
Reaction score
99
Location
Brazil
Hello guys,

I have a rank for task points, who organize it by storage value. In table i dont have null value or blank value, just numbers, but its kind buggy, like bellow:

1657371308515.png

This code for web page

PHP:
<?PHP
$storage_number = 176602;

$values = $SQL->query("SELECT name, level, value FROM players, player_storage WHERE group_id < 3 AND players.id = player_storage.player_id AND player_storage.key = ".$storage_number." ORDER BY value DESC LIMIT 50");

$main_content .= "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR><TD><CENTER><H2>Ranking for Task Points</H2></CENTER><BR>";
$main_content .= "<TABLE BORDER=0 CELLPADDING=4 CELLSPACING=1 WIDTH=100%></TABLE><TABLE BORDER=0 CELLPADDING=4 CELLSPACING=1 WIDTH=100%><TR BGCOLOR='".$config['site']['vdarkborder']."'><TD WIDTH=10% CLASS=whites><B>Rank</B></TD><TD WIDTH=50% CLASS=whites><B>Name</B></TD><TD WIDTH=10% CLASS=whites><B>Level</B></TD><TD WIDTH=30% CLASS=whites><B>Task Points</B></TD>";
foreach($values as $value)
{
if(!is_int($number_of_rows /2))
{
    $bgcolor = $config["site"]["darkborder"];
}
else
{
    $bgcolor = $config["site"]["lightborder"];
}
$number_of_rows++;
$main_content .= '<TR BGCOLOR="'.$bgcolor.'"><TD>'.$number_of_rows.'</TD><TD><a href="?subtopic=characters&name='.urlencode($value["name"]).'">'.$value["name"].'</a></TD><TD>'.$value["level"].'</TD><TD>'.$value["value"].'</TD></TR>';
}
$main_content .= '</TABLE></TD><TD WIDTH=5%><IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=1 HEIGHT=1 BORDER=0></TD><TD WIDTH=15% VALIGN=top ALIGN=right><TABLE BORDER=0 CELLPADDING=4 CELLSPACING=1><TR BGCOLOR="'.$config['site']['vdarkborder'].'"><TD CLASS=whites><B>Choose a skill</B></TD></TR><TR BGCOLOR="'.$config['site']['lightborder'].'"><TD><A HREF="?subtopic=highscores&list=experience" CLASS="size_xs">Experience</A><BR><A HREF="?subtopic=highscores&list=magic" CLASS="size_xs">Magic</A><BR><A HREF="?subtopic=highscores&list=shield" CLASS="size_xs">Shielding</A><BR><A HREF="?subtopic=highscores&list=distance" CLASS="size_xs">Distance</A><BR><A HREF="?subtopic=highscores&list=club" CLASS="size_xs">Club</A><BR><A HREF="?subtopic=highscores&list=sword" CLASS="size_xs">Sword</A><BR><A HREF="?subtopic=highscores&list=axe" CLASS="size_xs">Axe</A><BR><A HREF="?subtopic=highscores&list=fist" CLASS="size_xs">Fist</A><BR><A HREF="?subtopic=highscores&list=fishing" CLASS="size_xs">Fishing</A><BR><A HREF="?subtopic=reputation" CLASS="size_xs">Reputation</A><BR><A HREF="?subtopic=taskrank" CLASS="size_xs">Task Points</A><BR></TD></TR></TABLE></TD><TD><IMG SRC="'.$layout_name.'/images/blank.gif" WIDTH=10 HEIGHT=1 BORDER=0></TD></TR></TABLE>';

$main_content .= "</TR></TABLE>";

?>

Using @Gesior.pl 2012
 
Solution
It looks like your storage keeps strings, not integers, so results are sorted as strings.
Try to replace:
Code:
ORDER BY value DESC
with:
Code:
ORDER BY CAST(value AS DECIMAL) DESC

Gesior.pl

Mega Noob&LOL 2012
Senator
Premium User
Joined
Sep 18, 2007
Messages
2,776
Solutions
91
Reaction score
2,813
Location
Poland
GitHub
gesior
It looks like your storage keeps strings, not integers, so results are sorted as strings.
Try to replace:
Code:
ORDER BY value DESC
with:
Code:
ORDER BY CAST(value AS DECIMAL) DESC
 
Solution
Top