Beispiel #1
0
                    }
                }
                $score = $passed / $cases * 100;
                //WRITE PASSED
                if ($passed == $cases && !pass($task_id, $user_id)) {
                    $query = 'insert into `pass` (
						`pass_id`,
						`user_id`,
						`task_id`
						) values (NULL, ?, ?);';
                    $sql->prepare($query);
                    $sql->bind_param('ii', $user_id, $task_id);
                    $sql->execute();
                }
                //WRIET BEST
                $best = best($task_id, $user_id);
                if ($best['success'] && ($best['score'] < $score || abs($best['score'] - $score) < 1.0E-5 && $best['timeused'] > $timeused)) {
                    $query = 'update `best` set
						`score` = ?,
						`timeused` = ?,
						`text` = ?
						where `best_id` = ?;';
                    $sql->prepare($query);
                    $sql->bind_param('ddsi', $score, $timeused, $text, $best['best_id']);
                    $sql->execute();
                } else {
                    if (!$best['success']) {
                        $query = 'insert into `best` (
						`best_id`,
						`user_id`,
						`task_id`,
Beispiel #2
0
if (empty($_POST['guess'])) {
    if ($_SESSION['response'] == null) {
        $_SESSION['response'] = 'Pas de nombre';
    }
} else {
    $guess = $_POST['guess'];
    $_SESSION['score']++;
    if ($guess > $choice) {
        $_SESSION['response'] = "C'est moins";
    } elseif ($guess < $choice) {
        $_SESSION['response'] = "C'est plus";
    } else {
        $_SESSION['response'] = "C'est gagné";
        if (!isset($_SESSION['best_score']) || $_SESSION['best_score'] > $_SESSION['score']) {
            $_SESSION['best_score'] = $_SESSION['score'];
            best($pdo);
        }
        unset($_SESSION['choice']);
    }
    save($pdo);
}
/*  LEADER BOARD*/
function board($pdo)
{
    $q = $pdo->prepare("SELECT login, best_score\n                        from users\n                        ORDER BY best_score LIMIT 0,10");
    $q->execute();
    echo '<table border="1px">';
    echo '<th>Nom</th><th>Score</th>';
    while ($result = $q->fetch()) {
        echo '<tr>' . '<td>' . $result['login'] . '</td>' . '<td>' . $result['best_score'] . '</td>' . '</tr>';
    }
Beispiel #3
0
<?php

include 'globals.php';
if (isset($_GET['type'])) {
    $type = $_GET['type'];
}
switch ($type) {
    case 'best':
        best();
        break;
    case 'worst':
        worst();
        break;
    default:
        return "error";
        break;
}
function best()
{
    $conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
    // Check connection
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }
    $sql = "SELECT `style`, `addition`, (`good_votes` - `gross_votes`) AS karma from homebrewideas ORDER BY `karma` DESC LIMIT 0,10";
    $result = $conn->query($sql);
    $rows = array();
    while ($r = mysqli_fetch_assoc($result)) {
        $rows[] = $r;
    }
    print json_encode($rows);