while($row = $statement->fetch(PDO::FETCH_ASSOC))
$member[] = "${row["name"]} (${row["grope"]})";
$rank = 0;
$header = "";
$player = array(1);
$kicked = array(10000);
$memberCount = count($member);
$roundCount = ceil(log($memberCount) / log(2));
$round = array("čtvrtfinále", "semifinále", "finále", "vítěz");
for ($index = 0; $index < $roundCount; $index++)
for ($index2 = 0; $index2 < count($player); $index2 += 2)
array_splice($player, $index2 + 1, 0, $player[$index2] + pow(2, $index));
$playerCount = count($player);
for ($index = 0; $index < $playerCount - 1; $index++)
if ($player[$index] <= $playerCount - $memberCount)
{
$nextIndex = $index + 1;
for ($index2 = 0; $index2 < count($kicked) + 1; $index2++)
if ($kicked[$index2] > $player[$nextIndex])
{
array_splice($kicked, $index2, 0, $player[$nextIndex]);
break;
}
$player[$nextIndex] = 0xFFFF;
}
for ($index = 0; $index < count($kicked); $index++)
array_splice($member, $kicked[$index] - 1, 0, "");
for ($index = 0; $index < $roundCount + 1; $index++)
$header = "<th>".(count($round) > 0 ? array_pop($round)."</th>" : ($roundCount + 1 - $index).". kolo</th>").$header;
echo "<table id='bracket'><tr>", $header, "</tr>";
for ($index = 0; $index < $playerCount; $index++)
{
if ($player[$index] == 0xFFFF)
continue;
$argument = "";
$index2 = $playerCount - $index;
if ($player[$index + 1] == 0xFFFF)
$argument = " colspan=\"2\"";
echo "<tr><td$argument><span class=\"rank color", $rank++ % 2, "\">", $rank, "</span>", $member[$player[$index] - 1], "</td>";
while ($index2 % 2 == 0)
{
$argumentValue = 2 * ($playerCount - $index) / $index2;
$l = $index + $argumentValue;
for ($k = $index; $k < $l; $k++)
if ($player[$k] == 0xFFFF)
$argumentValue--;
if ($index2 != $playerCount - $index || !$argument)
echo '<td rowspan="', $argumentValue, '"></td>';
$index2 /= 2;
}
echo "</tr>";
}
echo "</table>";