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

// Check if transID is provided
if (!isset($_GET['transID'])) {
    echo json_encode(["error" => true, "message" => "Missing transID parameter."]);
    exit;
}

$transID = $connect->real_escape_string($_GET['transID']); // Sanitize input

// Query to fetch records ordered by descending order
$query = "SELECT * FROM creditsPayments WHERE transID = '$transID' ORDER BY id DESC";

$result = $connect->query($query);

$response = [];

if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $response[] = $row;
    }
    echo json_encode(["error" => false, "data" => $response]);
} else {
    echo json_encode(["error" => true, "message" => "No records found."]);
}
?>
