<?php
include 'db_config.php';

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="2024_Annual_Conference_Promotional_Materials.xls"');
header('Cache-Control: max-age=0');

// Fetch data from the database
$sql = "SELECT * FROM promotional_materials";
$result = $conn->query($sql);

// Start outputting the data as an HTML table
echo "<h3>2024 Annual Conference Promotional Materials List</h3>";
echo "<table border='1'>";
echo "<tr>
        <th>ID</th>
        <th>Full Name</th>
        <th>Email</th>
        <th>Phone</th>
        <th>Promotional Materials</th>
      </tr>";

// Loop through the data and output each row
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        echo "<tr>
                <td>" . $row['id'] . "</td>
                <td>" . $row['fullname'] . "</td>
                <td>" . $row['email'] . "</td>
                <td>" . $row['phone'] . "</td>
                <td>" . $row['promotional_materials'] . "</td>
              </tr>";
    }
} else {
    echo "<tr><td colspan='5'>No registered users found.</td></tr>";
}

echo "</table>";

// Close the database connection
$conn->close();
?>
