<?php
include 'db.php';

// Set headers for download
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=perishable_parameters.xls");
header("Pragma: no-cache");
header("Expires: 0");

// Fetch data
$res = $conn->query("
    SELECT p.id, per.name, p.qty_per_person, p.composition
    FROM perishable_parameters p
    JOIN perishables per ON per.id = p.perishable_id
    ORDER BY per.name ASC
");

// Start output
echo "<table border='1'>";
echo "<tr>
        <th>#</th>
        <th>Item</th>
        <th>Qty Per Person</th>
        <th>Composition</th>
      </tr>";

$i = 1;
while($row = $res->fetch_assoc()){
    echo "<tr>
            <td>{$i}</td>
            <td>{$row['name']}</td>
            <td>{$row['qty_per_person']}</td>
            <td>{$row['composition']}</td>
          </tr>";
    $i++;
}
echo "</table>";
exit;