<?php
// export.php
require 'config.php';

header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=transactions.xls");

$sql = "SELECT * FROM transactions ORDER BY date DESC";
$result = mysqli_query($conn, $sql);

echo "Date\tType\tAmount\tName\tPurpose/Usage\n";

if (mysqli_num_rows($result) > 0) {
    while($row = mysqli_fetch_assoc($result)) {
        echo $row['date'] . "\t" . $row['type'] . "\t" . $row['amount'] . "\t" . $row['name'] . "\t" . $row['purpose_usage'] . "\n";
    }
}
?>
