Search
 
SCRIPT & CODE EXAMPLE
 

PHP

single elimination php code

<?php

function is_player($round, $row, $team) {
    return $row == pow(2, $round-1) + 1 + pow(2, $round)*($team - 1);
}

$num_teams = 16;
$total_rounds = floor(log($num_teams, 2)) + 1;
$max_rows = $num_teams*2;
$team_array = array();
$unpaired_array = array();
$score_array = array();

for ($round = 1; $round <= $total_rounds; $round++) {
    $team_array[$round] = 1;
    $unpaired_array[$round] = False;
    $score_array[$round] = False;
}


echo "<table border="1" cellspacing="1" cellpadding="1">
";
echo "	<tr>
";

for ($round = 1; $round <= $total_rounds; $round++) {

    echo "		<td colspan="2"><strong>Round $round</strong></td>
";

}

echo "	</tr>
";

for ($row = 1; $row <= $max_rows; $row++) {

    echo "	<tr>
";

    for ($round = 1; $round <= $total_rounds; $round++) {
        $score_size = pow(2, $round)-1;
        if (is_player($round, $row, $team_array[$round])) {
            $unpaired_array[$round] = !$unpaired_array[$round];
            echo "		<td>Team</td>
";
            echo "		<td width="20"> </td>
";
            $team_array[$round]++;
            $score_array[$round] = False;
        } else {
            if ($unpaired_array[$round] && $round != $total_rounds) {
                if (!$score_array[$round]) {
                    echo "		<td rowspan="$score_size">Score</td>
";
                    echo "		<td rowspan="$score_size" width="20">$round</td>
";
                    $score_array[$round] = !$score_array[$round];
                }
            } else {
                echo "		<td colspan="2"> </td>
";
            }
        }

    }

    echo "	</tr>
";

}

echo "</table>
";

?>
Comment

PREVIOUS NEXT
Code Example
Php :: create associative array php by key value site:stackoverflow.com 
Php :: php variable undefined inside function argument 
Php :: laravel sendgrid using 2 possible authenticators. Authenticator LOGIN returned Expected response code 250 
Php :: cách nhúng php vào html 
Php :: xampp pdoexception could not find driver 
Php :: php type generic object 
Php :: SSL certificate problem: certificate has expired php 
Php :: change varchar limit in migration file. 
Php :: $usr= $_POST["user"]; $pswd= $_POST["pass"]; 
Php :: php function return type self 
Php :: Php countup from a date 
Php :: many posts in the isset 
Php :: .phtml 
Php :: php code for adding dara 
Php :: how to select and deselect all items without use name in laravel 
Php :: dump request in ci 
Php :: factorial program in php 
Php :: php input seperated by space 
Php :: how to show limited text in laravel on page 
Php :: Laravel function to check if image exist or not 
Php :: how get database structure in laravel 
Php :: php kurzschreibweise if 
Php :: seeder name singular or plural laravel 
Php :: how to access the name of menu in worpress 
Php :: laravel best practices tutorial 
Php :: ipay generate hash id 
Php :: setup wp cron from external / cpanel cron service 
Php :: update request php-salesforce-rest-api 
Php :: php int to indonesian rupiah 
Php :: laravel components 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =