<?php
include 'db.php';
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header("Content-Disposition: attachment; filename=daftar_onderdil_" . date("Ymd_His") . ".xls");
header("Pragma: no-cache");
header("Expires: 0");

$result = $conn->query("SELECT * FROM onderdil");

echo "<table border='1'>";
echo "<tr>
        <th>Nama Onderdil</th>
        <th>Harga Beli</th>
        <th>Harga Jual</th>
        <th>Stok</th>
      </tr>";

while ($row = $result->fetch_assoc()) {
    echo "<tr>
            <td>" . htmlspecialchars($row['Nama_onderdil']) . "</td>
            <td>" . htmlspecialchars($row['Harga_beli']) . "</td>
            <td>" . htmlspecialchars($row['Harga_jual']) . "</td>
            <td>" . htmlspecialchars($row['Stok']) . "</td>
          </tr>";
}

echo "</table>";

$conn->close();
?>
