<?php
// Include file koneksi database
require_once 'Database.php';

// Koneksi ke database
$pdo = Database::connect();

// Ambil semua data dari tabel tb_gabungan
$stmt = $pdo->query("SELECT * FROM tb_gabungan");
$gabunganData = $stmt->fetchAll(PDO::FETCH_ASSOC);

// Tutup koneksi ke database
Database::disconnect();

// Mengatur header untuk mengunduh file Excel
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=laporan-excel.xls");
header("Pragma: no-cache");
header("Expires: 0");

?>
<h2>Data Gabungan</h2>
<table border="1">
    <thead>
        <tr>
            <th>ID</th>
            <th>Nama</th>
            <th>User ID</th>
            <th>Jenis Kelamin</th>
            <th>umur</th>
            <th>Nomor Telepon</th>
            <th>Detak Jantung</th>
            <th>Oksigen</th>
            <!-- <th>Suhu</th> -->
            <th>Tanggal</th>
            <th>Status</th>
        </tr>
    </thead>
    <tbody>
        <?php if ($gabunganData): ?>
            <?php foreach ($gabunganData as $row): ?>
                <tr>
                    <td><?php echo htmlspecialchars($row['id']); ?></td>
                    <td><?php echo htmlspecialchars($row['name']); ?></td>
                    <td><?php echo htmlspecialchars($row['user_id']); ?></td>
                    <td><?php echo htmlspecialchars($row['gender']); ?></td>
                    <td><?php echo htmlspecialchars($row['umur']); ?></td>
                    <td><?php echo htmlspecialchars($row['mobile']); ?></td>
                    <td><?php echo htmlspecialchars($row['detakjantung']); ?></td>
                    <td><?php echo htmlspecialchars($row['oksigen']); ?></td>

                    <td><?php echo htmlspecialchars($row['tanggal']); ?></td>
                    <td><?php echo htmlspecialchars($row['status']); ?></td>
                </tr>
            <?php endforeach; ?>
        <?php else: ?>
            <tr>
                <td colspan="11" class="text-center">Tidak ada data.</td>
            </tr>
        <?php endif; ?>
    </tbody>
</table>
