<?php
// select_past_records.php
header("Content-Type: application/json");

$servername = "localhost";
$username = "myprojec_allytec";
$password = "allytech@2019";
$dbname = "myprojec_patient"; // Replace with your actual database name

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die(json_encode(['status' => 'error', 'message' => 'Connection failed: ' . $conn->connect_error]));
}

// SQL query to fetch records where ddate < current date
$sql = "SELECT * FROM donation_tbl WHERE ddate < CURDATE() order by id desc";

$result = $conn->query($sql);

if ($result->num_rows > 0) {
    $records = [];
    while ($row = $result->fetch_assoc()) {
        $records[] = $row;
    }
    echo json_encode(['status' => 'success', 'data' => $records]);
} else {
    echo json_encode(['status' => 'success', 'message' => 'No past records found.']);
}

$conn->close();
?>
