Stránka 1 z 1

Pomoc s php kodíkem :D

Napsal: 23 dub 2013 19:13
od Gizzer2
Zdravím,
potřeboval bych poradit jak zaimpletovat datum do tohoto kodu (zde je vidět funkce kodu http://michales.eu/losovani.php):

Kód: Vybrat vše

<?php


function main() {
    ?>
    <style>
    body,

#web_all { width: 500px; margin: 0px auto; background: #4bc2ec url(http://hdwallpapersdesktop.com/wallpapers/wp-content/uploads/2011/09/05/Ice-hockey-Wallpaper-NHL-Wallpaper-4.jpg) center top no-repeat;background-attachment: fixed; }
    input, textarea { display: block; margin-bottom: 1em; }
    label { font-weight: bold; display: block; }   
    </style>
 <center> <h1>Rozlosování zápasů</h1>

    <?php
    // Find out how many teams we want fixtures for.
    if (! isset($_GET['teams']) && ! isset($_GET['names'])) {
        print get_form();
    } else {
        # XXX check for int
        print show_fixtures(isset($_GET['teams']) ?  nums(intval($_GET['teams'])) : explode("\n", trim($_GET['names'])));
    }
}

function nums($n) {
    $ns = array();
    for ($i = 1; $i <= $n; $i++) {
        $ns[] = $i;
    }
    return $ns;
}

function show_fixtures($names) {
    $teams = sizeof($names);

    print "<p>Rozlosování pro $teams týmy.</p>";

    // If odd number of teams add a "ghost".
    $ghost = false;
    if ($teams % 2 == 1) {
        $teams++;
        $ghost = true;
    }
   
    // Generate the fixtures using the cyclic algorithm.
    $totalRounds = $teams - 1;
    $matchesPerRound = $teams / 2;
    $rounds = array();
    for ($i = 0; $i < $totalRounds; $i++) {
        $rounds[$i] = array();
    }
   
    for ($round = 0; $round < $totalRounds; $round++) {
        for ($match = 0; $match < $matchesPerRound; $match++) {
            $home = ($round + $match) % ($teams - 1);
            $away = ($teams - 1 - $match + $round) % ($teams - 1);
            // Last team stays in the same place while the others
            // rotate around it.
            if ($match == 0) {
                $away = $teams - 1;
            }
            $rounds[$round][$match] = team_name($home + 1, $names)
                . ' <font color="red">VS</font> '. team_name($away + 1, $names);
        }
    }

    // Interleave so that home and away games are fairly evenly dispersed.
    $interleaved = array();
    for ($i = 0; $i < $totalRounds; $i++) {
        $interleaved[$i] = array();
    }
   
    $evn = 0;
    $odd = ($teams / 2);
    for ($i = 0; $i < sizeof($rounds); $i++) {
        if ($i % 2 == 0) {
            $interleaved[$i] = $rounds[$evn++];
        } else {
            $interleaved[$i] = $rounds[$odd++];
        }
    }

    $rounds = $interleaved;

    // Last team can't be away for every game so flip them
    // to home on odd rounds.
    for ($round = 0; $round < sizeof($rounds); $round++) {
        if ($round % 2 == 1) {
            $rounds[$round][0] = flip($rounds[$round][0]);
        }
    }
   
    // Display the fixtures       
    for ($i = 0; $i < sizeof($rounds); $i++) {
        print "<p>Kolo " . ($i + 1) . "</p>\n";
        foreach ($rounds[$i] as $r) {
            print $r . "<br />";
        }
        print "<br />";
    }
    print "<p>Druhá polovina je zrcadlem první polovině</p>";
    $round_counter = sizeof($rounds) + 1;
    for ($i = sizeof($rounds) - 1; $i >= 0; $i--) {
        print "<p>Kolo " . $round_counter . "</p>\n";
        $round_counter += 1;
        foreach ($rounds[$i] as $r) {
            print flip($r) . "<br />";
        }
        print "<br />";
    }
    print "<br />";

    if ($ghost) {
        print "Matches against team " . $teams . " are byes.";
    }
}

function flip($match) {
    $components = explode(' v ', $match);
    return $components[1] . " v " . $components[0];
}

function team_name($num, $names) {
    $i = $num - 1;
    if (sizeof($names) > $i && strlen(trim($names[$i])) > 0) {
        return trim($names[$i]);
    } else {
        return $num;
    }
}

function get_form() {
    $s = '';
    $s = '<p><font color="red">Zadejte počet týmů nebo jména týmů</p>' . "\n";
    $s .= '<form action="' . $_SERVER['SCRIPT_NAME'] . '">' . "\n";
    $s .= '<label for="teams">Počet týmů</label><input type="text" name="teams" />' . "\n";
    $s .= '<input type="submit" value="Rozlosování" />' . "\n";
    $s .= '</form>' . "\n";

    $s .= '<form action="' . $_SERVER['SCRIPT_NAME'] . '">' . "\n";
    $s .= '<div><strong>nebo</strong></div>' . "\n";
    $s .= '<label for="names">Jméno týmu (Na každý řadek jméno jednoho týmu)</label>'
        . '<textarea name="names" rows="8" cols="40"></textarea>' . "\n";
    $s .= '<input type="submit" value="Rozlosování" />' . "\n";
    $s .= "</form>\n";
    return $s;
}

main();

?>
      </center>

Jde mi o to že by se přidal další imput, kde by se zadal datum a ve výsledku by se připočítaval den.
Doufám že jsem to vysvětlil k pochopení. Pro jistotu si vyzkoušejte funkci na stránce http://michales.eu/losovani.php
Zadejte počet týmu a klikněte na rozlosování. Vyjede vám výsledek a bude tam kolo 1, kolo 2 atd. Takhle bych chtěl i ten datum aby se přičítal jako ty kola.
Díky za radu.

Re: Pomoc s php kodíkem :D

Napsal: 24 dub 2013 16:57
od Gizzer2
Řešení:

Kód: Vybrat vše

for($i = 0; $i <= 10; $i++)
echo date('d.m.Y', strtotime($_GET['datum'] . ' +' . $i . ' day')). '<br>'; 

Re: Pomoc s php kodíkem :D

Napsal: 24 dub 2013 21:25
od CZechBoY
stačí jednou zjistit hodnotu timestamp v integeru a potom přičítat 60*60*24*$i