• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

PHP Sortowanie ;P

Potar

SocialWorld
Senator
Joined
Mar 1, 2009
Messages
1,661
Reaction score
125
Location
Warsaw, Poland
Nie mam co obijać w bawełnę, nie znam się zbytnio na .PHP to także nie mogę sobie z tym poradzić:

1. Chcę aby ustawić limit widzianych graczy do 30 w quest makers (jak dodam na koniec LIMIT 0, 30 albo LIMIT 30 pokazuje pierwsze 30 charów z wynikiem 0% a jak bez limitu, pokazuje wszystie postacie na serwerze sortując od najwyższego, czyli dobrze (a chcę ograniczyć do 30 wyników).
PHP:
<?PHP
$quest_list = $config['site']['quests2'];
if(!$quest_list)
{
        $main_content .= 'Check your Quests on Config';
        break;
}
$players = $SQL->query('SELECT * FROM players WHERE deleted = 0 AND group_id < '.$config['site']['players_group_id_block'].' AND account_id != 1' );
$nr_gracza = 0;
$main_content .= '<h2 align="center">Top 30 Quest Makers on</h2>
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%>
<table border="0" cellspacing="1" cellpadding="4" width="100%">
	<tr bgcolor="#505050" >
		<td class="white" style="text-align: center; font-weight: bold;" >Pos</td>
		<td class="white" style="text-align: center; font-weight: bold;" >Name</td>
		<td class="white" style="text-align: center; font-weight: bold; width: 255px" width="255">Progress</td>
		<td class="white" style="text-align: center; font-weight: bold;" width="50">%</td>
	</tr><tr bgcolor="#D4C0A1">';
foreach ($players as $player) 
{
        $ilosc_questow_wykonanych = 0;
        $ilosc_questow = 0;
        foreach($quest_list as $storage => $name)
        {
                $ilosc_questow++;
                $quest_baza = $SQL->query("SELECT * FROM player_storage WHERE player_id = ".$player['id']." AND `key` = '".$quest_list[$storage]."' " );
                foreach($quest_baza as $idd)
                        $ilosc_questow_wykonanych++;
        }
        $ilosc_procent =($ilosc_questow_wykonanych / $ilosc_questow) * 100;
        $gracz_wynik[$player['name']] = $ilosc_procent;
}
$gracze_wyniki = arsort($gracz_wynik);
foreach($gracz_wynik as $gracz => $procent)
{
        if(is_int($nr_gracza / 2))
                $bgcolor = $config['site']['darkborder'];
        else
                $bgcolor = $config['site']['lightborder'];
        $nr_gracza++;
        $main_content .= '<TR BGCOLOR="'.$bgcolor.'"><TD width=10%><center>'.$nr_gracza.'</center></TD><TD width=50%><center><a href="?subtopic=characters&name='.$gracz.'">'.$gracz.'</a></center></td><td><div title="'.number_format($procent,0).'%" style="width: 100%; height: 10px; border: 1px solid #000;"><div style="background: green; width: '.$procent.'%; height: 10px;"></td><td>'.number_format($procent,0).'%</td></tr>';
		}
$main_content .= '</table>';
?>
2 oraz 3, chcę by sortowało mi wynik od najwyższego value, a nie pokazywało po prostu po ID, kto wyżej w bazie ten wyżej w topce:

2.
PHP:
<?php
	$result = $SQL->query("SELECT `players`.`name`, `player_storage`.`value` FROM `players` JOIN `player_storage` ON `players`.`id` = `player_storage`.`player_id` WHERE `player_storage`.`key` = 72500 ORDER BY `player_storage`.`key` DESC LIMIT 0, 10;");
	    $main_content .= '<div style="text-align: center; font-weight: bold;"><h2>Top 10 of Paw & Fur points ' . $config['server']['serverName'] . '</h2></div> 
<center><table border="0" cellspacing="1" cellpadding="4" width="100%"> 
    <tr bgcolor="'.$config['site']['vdarkborder'].'"> 
        <td width="10%"><b><font color=white><center>Pos</font></center></b></td> 
        <td width="30%"><b><font color=white><center>Player Name</center></b></font></td> 
        <td width="20%"><b><font color=white><center>Paw & Fur points</center></b></font></td> 
        <td width="20%"><b><font color=white><center>Rank</center></b></font></td> 
    </tr>'; 
	$i = 0; 
	foreach ($result as $entry)
	{ 
    $i++; 
	$main_content .= '<tr bgcolor="' . (is_int($i / 2) ? $config['site']['lightborder'] : $config['site']['darkborder']). '"> ';
	$main_content .= "
	<td><center>".$i." </center></td>
	<td><b><center>". $entry["name"] ."</center></b></td>
	<td><center>". $entry["value"] ."</center></td>";
$rank = $entry["value"];
if ($rank >= 0){$rank_name = 'None';} 
if ($rank >= 20){$rank_name = 'Ranger';} 
if ($rank >= 40){$rank_name = 'Game Hunter';} 
if ($rank >= 70){$rank_name = 'Trophy Hunter';} 
if ($rank >= 100){$rank_name = 'Elite Hunter';} 

	$main_content .= "<td><center>".$rank_name."</center></td></td></tr>";
	} 
	$main_content .= '</table><br />'; 
?>

3.
PHP:
<?php
	$result = $SQL->query("SELECT `players`.`name`, `player_storage`.`value` FROM `players` JOIN `player_storage` 
	ON `players`.`id` = `player_storage`.`player_id` WHERE `player_storage`.`key` = 73339 
	ORDER BY `player_storage`.`key` DESC LIMIT 0, 10;");
	    $main_content .= '<div style="text-align: center; font-weight: bold;"><h2>Top 10 of Reputation on ' . $config['server']['serverName'] . '</h2></div> 
<center><table border="0" cellspacing="1" cellpadding="4" width="100%"> 
    <tr bgcolor="'.$config['site']['vdarkborder'].'"> 
        <td width="10%"><b><font color=white><center>Pos</font></center></b></td> 
        <td width="25%"><b><font color=white><center>Player Name</center></b></font></td> 
        <td width="15%"><b><font color=white><center>Reputation</center></b></font></td> 
        <td width="30%"><b><font color=white><center>Player Killer Level</center></b></font></td> 
    </tr>'; 

	$i = 0; 
	foreach ($result as $entry)
	{ 
    $i++; 
	$main_content .= '<tr bgcolor="' . (is_int($i / 2) ? $config['site']['lightborder'] : $config['site']['darkborder']). '"> 
	<td><center>'.$i.' </center></td>
	<td><b><center><a href="?subtopic=characters&name='. $entry["name"] .'">'. $entry["name"] .'</a></center></b></td>
	<td><center>'. $entry["value"] .'</center></td>';
$rank = $entry["value"];
if ($rank >= 0){$rank_name = '<img src="images/redskull.gif"/>';} 
if ($rank >= 50){$rank_name = '<img src="images/redskull.gif"/><img src="images/redskull.gif"/>';} 
if ($rank >= 100){$rank_name = '<img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/>';} 
if ($rank >= 200){$rank_name = '<img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/>';} 
if ($rank >= 300){$rank_name = '<img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/>';} 
if ($rank >= 400){$rank_name = '<img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/>';} 
if ($rank >= 500){$rank_name = '<img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/>';} 
if ($rank >= 600){$rank_name = '<img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/>';} 
if ($rank >= 700){$rank_name = '<img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/>';} 
if ($rank >= 800){$rank_name = '<img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/>';} 
if ($rank >= 900){$rank_name = '<img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/>';} 
if ($rank >= 1000){$rank_name = '<img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/><img src="images/redskull.gif"/>';} 

	$main_content .= "<td><center>".$rank_name."</center></td></td></tr>";
	}
	$main_content .= '</table><br />'; 
?>
 
to akurat jest mysql
dodajesz w zapytaniu sort by nazwapola ascending lub descending w zależności od kierunku sortowania
 
1. FIXED
- W pierwszym dodałem po prostu warunek:

if ($nr_gracza >= 1 and $nr_gracza <=30) wtedy pokażę wartość w tabeli

ale i tak mimo tego przelatuje sałą bazę ; / Load time: 8.6478 seconds




I pokazuje 30 wyników.

Ale z 2 oraz 3 nie mogę sobie poradzić ;/
 
Last edited:
1. FIXED
- W pierwszym dodałem po prostu warunek:

if ($nr_gracza >= 1 and $nr_gracza <=30) wtedy pokażę wartość w tabeli

ale i tak mimo tego przelatuje sałą bazę ; / Load time: 8.6478 seconds




I pokazuje 30 wyników.

Ale z 2 oraz 3 nie mogę sobie poradzić ;/

Dodaj cache na 5 min i po problemie :P
 
1
PHP:
<?PHP
$quest_list = $config['site']['quests2']; 

$main_content .= '<h2 align="center">Top 30 Quest Makers on</h2> 
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%> 
<table border="0" cellspacing="1" cellpadding="4" width="100%"> 
    <tr bgcolor="#505050" > 
        <td class="white" style="text-align: center; font-weight: bold;" >#</td> 
        <td class="white" style="text-align: center; font-weight: bold;" >Name</td> 
        <td class="white" style="text-align: center; font-weight: bold; width: 255px" width="255">Progress</td> 
        <td class="white" style="text-align: center; font-weight: bold;" width="50">%</td> 
    </tr><tr bgcolor="#D4C0A1">'; 

$ids = join(',',$quest_list);  
	

foreach($SQL->query("SELECT `player_id`, COUNT(*) FROM `player_storage` WHERE `key` IN ($ids) AND `value` = 1 GROUP BY `player_id` ORDER BY COUNT(*) DESC LIMIT 0, 30") as $result) 
{
	$i++;
	foreach($SQL->query("SELECT name FROM `players` WHERE id=".$result['player_id']) as $res)
		$main_content .= '
		<tr class="'.(is_int($i/2)?'Odd':'Even').'">
			<td align="center"><b>'.$i.'.</b></td>
			<td align="center"><a href="?subtopic=characters&amp;name='.htmlspecialchars($res[0]).'">'.$res[0].'</a></td>
			<td>
				<div>
					<div style="background:url(http://www.bbcode.pl/images/prog_grey.png) repeat-x; background-color: #cccccc; border: 1px solid black; width:200px; margin-top: 2px; align: center;">
						<div style="background:url(http://www.bbcode.pl/images/prog_green.png) repeat-x; background-color: #008040; font-weight:bold; font-size: 12px; width:'.round((($result[1]*100)/count($quest_list)), 2).'%; height:14px;">
							<center><font color="black"><b>['.$result[1].'/'.count($quest_list).']</font></center>
						</div>
					</div>
				</div>
			</td>
			<td>
				<center><b>'.round((($result[1]*100)/count($quest_list)), 2).'</b></center>
			</td>
		</tr>';
}

$main_content .= '</table>'; 
?>

2,3
PHP:
ORDER BY `player_storage`.`value` DESC LIMIT 0, 10;
 
Last edited:
ty, ja za bardzo nie jestem specem czy coś, ale w poszukiwaniu największych wartości do najmniejszych to chyba musi przelecieć całą bazą bo przecież równie dobrze rekord z wartośćią "20" może być na początku jak i na końcu w bazie, no chyba, że jest jakieś sortowanie wcześniej ustawione
 
w zapytaniu sort albo order by i tyle, z resztą już o tym wspominałem

Dobra wpisałem po raz kolejny :

ORDER BY `player_storage`.`value` DESC LIMIT 30;");

Ujrzałem błąd :D

Ale:

Sortuje mi jakoś dziwnie:

1. Name 9 pkt
2. Name 8pt
3. Name 74pkt
4. ITP 7pkt
5. ITD 6pkt

Nie liczy 74 jako wyższej od 9.
 
Last edited:
używasz może tfsa po 0.3.6?(0.3.6 miał storage jeszcze chyba liczbowe a dalej mogą zawierać stringi)
Sortowanie stringów takie łatwe nie jest i widać mysql sobie chyba nie radzi
jak ktoś nie znajdzie ci sposobu zostaje wczytanie całej bazy i sortowanie pehapem :/
 
Back
Top