コード例 #1
0
function updateTable($teamCollections, $scoresCollection)
{
    if (!scoresAreOK($scoresCollection)) {
        echo '<span style="color:red;text-align:center;">Scorurile trebuie sa fie intre 0 - 9!</span>';
    } else {
        if (!teamsAreUnique($teamCollections)) {
            echo '<span style="color:red;text-align:center;">Intr-o etapa o echipa joaca un singur meci impotriva oricarei alte echipe!</span>';
        } else {
            for ($count = 0; $count < 14; $count = $count + 2) {
                if ($scoresCollection[$count] == $scoresCollection[$count + 1]) {
                    resolveDrawn($teamCollections[$count], $scoresCollection[$count], $teamCollections[$count + 1]);
                } else {
                    if ($scoresCollection[$count] > $scoresCollection[$count + 1]) {
                        resolveWin($teamCollections[$count], $scoresCollection[$count], $scoresCollection[$count + 1], $teamCollections[$count + 1]);
                    } else {
                        resolveWin($teamCollections[$count + 1], $scoresCollection[$count + 1], $scoresCollection[$count], $teamCollections[$count]);
                    }
                }
            }
        }
    }
}
コード例 #2
0
/**
 * Created by PhpStorm.
 * User: Lucian
 * Date: 13.12.2015
 * Time: 16:33
 */
$teams = json_decode(stripslashes($_GET['teams']));
$scores = json_decode(stripslashes($_GET['scores']));
for ($i = 0; $i <= 16; $i = $i + 2) {
    if ($scores[$i] == $scores[$i + 1]) {
        resolveDrawn($teams[$i], $scores[$i], $teams[$i + 1]);
    } else {
        if ($scores[$i] > $scores[$i + 1]) {
            resolveWin($teams[$i], $scores[$i], $scores[$i + 1], $teams[$i + 1]);
        } else {
            resolveWin($teams[$i + 1], $scores[$i + 1], $scores[$i], $teams[$i]);
        }
    }
}
function resolveDrawn($team1, $goals, $team2)
{
    $servername = "localhost";
    $username = "******";
    $password = "******";
    $dbname = "premierleague";
    $conn = new mysqli($servername, $username, $password, $dbname);
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    $sql = "UPDATE premierleague.premierleague SET played=played+1, draws=draws+1, goals_for=goals_for+" . $goals . ", goals_against=goals_against+" . $goals . ", points=points+1 WHERE club='" . $team1 . "';";
    if ($conn->query($sql) !== TRUE) {