<?php

header('Content-Type: application/json');
include 'config.php';

/* =========================
   GET ALL ORDERS
========================= */

$sql = "SELECT * FROM topup_orders ORDER BY id DESC";
$result = $conn->query($sql);

$orders = [];

if ($result && $result->num_rows > 0) {

    while ($row = $result->fetch_assoc()) {
        $orders[] = $row;
    }

    echo json_encode([
        "status" => "success",
        "total"  => count($orders),
        "data"   => $orders
    ]);

} else {

    echo json_encode([
        "status" => "success",
        "total"  => 0,
        "data"   => []
    ]);
}

$conn->close();

?>