• 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!

AAC Alphabetical sorting in a loop

Unknown Soldier

Mapping a map
Joined
Oct 30, 2010
Messages
263
Solutions
11
Reaction score
621
Hi everyone!


I have a little request for those, who are good at php. I have a subpage where all statistics about number of killed monsters are. It works perfectly fine, however I feel it is a little bit too messy, because the table is not sorted in any way. So I would like to ask you for help in adding alpabetical sorting to the list, so the monsters are sorted from A to Z.

If there were a feature that the table could be sorted descending and ascending, it would be perfect!

Thanks in advance!



killedmonsters.PNG


PHP:
<?php
 
/* Scrip by zonet */
$kills = $config['site']['creatureKills'];
$limit = $config['site']['creatureKillShowLimit'];
$main_content .= '<table border="0px" cellspacing="1px" cellpadding="4px" width="100%">
           <TR BGCOLOR="'.$config['site']['vdarkborder'].'" style="color: white;"><th>Creature</th><th>'.$limit.'  Top Killers</th></tr>';
$row = 1;

    foreach($kills as $name => $storage) {
    $qa = $SQL->query('SELECT `player_storage`.`player_id`, `player_storage`.`key`, `player_storage`.`value` AS `value`, `players`.`id`, `players`.`name` AS `name` FROM `player_storage` LEFT JOIN `players` ON `player_storage`.`player_id` = `players`.`id` WHERE `player_storage`.`key` = '.$storage.' ORDER BY ABS(value) DESC LIMIT '.$limit)->fetchAll();
    $color = ( $row % 2 ? $config['site']['darkborder'] : $config['site']['lightborder']);
    $row++;
    $main_content .= '<tr bgcolor="'.$color.'"><td width="40%" style="font-size: 10pt; font-weight: bold; "><center>'.(ucfirst($name)).'</center></td><td>';
        $a = 0;
        foreach( $qa as $q )
        {
            $a++;

            $main_content .= '<b>'.$a.'.</b> <a href="?subtopic=characters&name='.urlencode($q['name']).'">'.$q['name'].'</a> (Kills:  '.$q['value'].') </font></font></font><br />';
        }
    }
    $main_content .= '</td></table>';
?>
 
Was it really so easy?

I have solved it outside this script sorting the table content in just an excel, however it's nice to see that solution is simple and my quetion was on really low level... I feel stupid...
Thank you both, I will use sort/rsort function :)
 
Sometimes solutions are already in the internet, even if it's not in OTLand, for example if you search "sort php" the first link will give you the same answer I provided
 
Back
Top