Visualizzazione dei risultati da 1 a 3 su 3

Discussione: Calendario fantacalcio

  1. #1
    Utente di HTML.it
    Registrato dal
    Nov 2012
    Messaggi
    80

    Calendario fantacalcio

    Cia a tutti sono nuovo del forum e nn sono molto pratico in php.
    Sto facendo un sito sul fantacalcio, e ho travato un programma php su internet:
    function main() {
    ?>
    <style>
    input, textarea { display: block; margin-bottom: 1em; }
    label { font-weight: bold; display: block; }
    </style>
    <?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 "

    Calendario per $teams squadre.</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)
    . " v " . 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 "

    Giornata " . ($i + 1) . "</p>\n";
    foreach ($rounds[$i] as $r) {
    print $r . "
    ";
    }
    print "
    ";
    }
    print "

    Il calendario si ripete a seconda del numero di giornate</p>";
    $round_counter = sizeof($rounds) + 1;
    print "
    ";
    if ($ghost) {
    print "La squadra " . $teams . " è un 'fantasma'.";
    }
    }

    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 = '

    Inserisci il numero si squadre OPPURE nome delle squadre</p>' . "\n";
    $s .= '<form action="' . $_SERVER['SCRIPT_NAME'] . '">' . "\n";
    $s .= '<label for="teams">Numero di squadre</label><input type="text" name="teams" />' . "\n";
    $s .= '<input type="submit" value="Genera calendario" />' . "\n";
    $s .= '</form>' . "\n";

    $s .= '<form action="' . $_SERVER['SCRIPT_NAME'] . '">' . "\n";
    $s .= '<div>Oppure</div>' . "\n";
    $s .= '<label for="names">Nomi delle squadre(una per linea)</label>'
    . '<textarea name="names" rows="8" cols="40"></textarea>' . "\n";
    $s .= '<input type="submit" value="Genera Calendario" />' . "\n";
    $s .= "</form>\n";
    return $s;
    }

    main();

    ?>
    Questo programma provato in easy php funziona correttamente. Ma quando lo carico sul mio sito nn funziona, praticamente quando inserisco i nomi delle squadre al posto di darmi il calendario mi fa tornare alla home page.
    Cosa devo modificare??????

  2. #2
    Utente di HTML.it
    Registrato dal
    Nov 2012
    Messaggi
    80
    Preciso il programma funziona però quando lo carico sulla pagina interna del sito, e vado a fare crea calendario mi carica la pagina principale xkè?

  3. #3
    Moderatore di JavaScript L'avatar di br1
    Registrato dal
    Jul 1999
    Messaggi
    19,998
    Se ripulisci il codice da tutta la mercanzia PHP, che non si tratta in questo forum, e posti solo quello che riceve il browser forse ti si potrebbe anche cercare di aiutarti....
    Il guaio per i poveri computers e' che sono gli uomini a comandarli.

    Attenzione ai titoli delle discussioni: (ri)leggete il regolamento
    Consultate la discussione in rilievo: script / discussioni utili
    Usate la funzione di Ricerca del Forum

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.