<?php
$top = 40; //kolik nejlepších

function getTime($total)
{
  $dny = (int)($total / 86400);
  $total = $total - ($dny * 86400);
  $hodiny = (int)($total / 3600);
  $total = $total - ($hodiny * 3600);
  $minuty = (int)($total / 60);

  $cas = $dny.'d '.$hodiny.'h '.$minuty.'m';
  return($cas);
}

function getOnline($online)
{
  if($online == 1) $status = '<span style="color: green;">Online</span>';
    else $status = '<span style="color: red;">Offline</span>'; 
  return($status);
}

$Realm = new Realm($System, $_COOKIE['RealmIndex']);
$db = $Realm->CharactersDatabase;

$sql = 'SELECT name, totaltime, online FROM characters ORDER BY totaltime DESC LIMIT '.$top;
$result = $db->query($sql);

$i = 0;
echo('<h3 class="PageTitle">Nejlepších '.$top.' herních časů</h3>');

echo('<table class="SimpleTable">');      
while($vypis = $result->fetch_assoc())
{    
  $i = $i + 1;
  echo('<tr><td>'.$i.')<th>'.$vypis['name'].'</th>
        <td>'.getTime($vypis['totaltime']).'</td>
        <td>'.getOnline($vypis['online']).'</td></tr>');

}
echo('</table>');

?>