<?php
require_once 'config.php';

if (isset($_POST['update_time'])) {
    $id = $_POST['id'];
    $result_time = $_POST['result_time'];

    $stmt = $db->prepare("UPDATE markets SET result_time = ? WHERE id = ?");
    $stmt->execute([$result_time, $id]);

    echo "Result time berhasil diupdate!";
}

$markets = $db->query("SELECT * FROM markets")->fetchAll(PDO::FETCH_ASSOC);
?>
<h2>Update Result Time</h2>
<form method="POST">
    <select name="id">
        <?php foreach ($markets as $m): ?>
            <option value="<?= $m['id'] ?>"><?= $m['name'] ?> (<?= $m['result_time'] ?>)</option>
        <?php endforeach; ?>
    </select>
    <input type="time" name="result_time" required>
    <button type="submit" name="update_time">Update</button>
</form>
