<?php
$draw_type = $_POST['draw_type'];
$table_name = '';

switch ($draw_type) {
    case 'talaga':
        $table_name = 'atur_talaga';
        break;
    case 'BOGOR':
        $table_name = 'atur_bogor';
        break;
    default:
        echo json_encode(['success' => false]);
        exit();
}

// Koneksi ke database
$connection = new mysqli('localhost', 'root', '', 'pasaran_dublinpools');

if ($connection->connect_error) {
    die("Connection failed: " . $connection->connect_error);
}

// Query untuk mengambil data berdasarkan kondisi id_situs = 1
$sql = "SELECT draw_time, draw_end FROM $table_name WHERE id_situs = 1";
$result = $connection->query($sql);

if ($result->num_rows > 0) {
    $row = $result->fetch_assoc();
    echo json_encode(['success' => true, 'draw_time' => $row['draw_time'], 'draw_end' => $row['draw_end']]);
} else {
    echo json_encode(['success' => false]);
}

$connection->close();
?>