<?php
    require_once 'data.php';
    $data_result = array();
    // Results
    $draw1 = "SELECT * FROM justicewonder WHERE is_result = 1 AND trashed = 0 ORDER BY id DESC";
    $qdraw1 = mysqli_query($data, $draw1);
    
    if(mysqli_num_rows($qdraw1) > 0) {
        while($fdraw1 = mysqli_fetch_assoc($qdraw1)){
            $pr1 = $fdraw1['prize1'];
            $pr2 = $fdraw1['prize2'];
            $pr3 = $fdraw1['prize3'];
            $pr4 = $fdraw1['speciala1'];
            $pr5 = $fdraw1['speciala2'];
            $pr6 = $fdraw1['speciala3'];
            $pr7 = $fdraw1['speciala4'];
            $pr8 = $fdraw1['speciala5'];
            $pr9 = $fdraw1['consola1'];
            $pr10 = $fdraw1['consola2'];
            $pr11 = $fdraw1['consola3'];
            $pr12 = $fdraw1['consola4'];
            $pr13 = $fdraw1['consola5'];

            $data_result[] = array(
                'ticket_no' => $fdraw1['id'],
                'day' => $fdraw1['hari'],
                'start_date' => $fdraw1['mulaitgl'],
                'prize' => intval($fdraw1['top_prize']),
                'prize_1' => intval($pr1),
                'prize_2' => intval($pr2),
                'prize_3' => intval($pr3),
                'prize_4' => intval($pr4),
                'prize_5' => intval($pr5),
                'prize_6' => intval($pr6),
                'prize_7' => intval($pr7),
                'prize_8' => intval($pr8),
                'prize_9' => intval($pr9),
                'prize_10' => intval($pr10),
                'prize_11' => intval($pr11),
                'prize_12' => intval($pr12),
                'prize_13' => intval($pr13),
                );
            }
    }


        header('Content-Type: application/json');
        header("Access-Control-Allow-Origin: *"); // Replace with your Next.js app's origin
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
        header("Access-Control-Allow-Methods: GET");

     echo json_encode($data_result)

?>