<?php
require('config.php');

// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);

$response = [];

// Query to fetch all records from batch_entries
$query = "SELECT * FROM batch_entries ORDER BY id DESC";
$result = $connect->query($query);

if ($result) {
    $batchEntries = [];
    while ($row = $result->fetch_assoc()) {
        $batchEntries[] = $row;
    }
    
    $response['error'] = false;
    $response['data'] = $batchEntries;
} else {
    $response['error'] = true;
    $response['message'] = "Failed to retrieve batch entries: " . $connect->error;
}

// Return JSON response
echo json_encode($response);
?>
