connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Fetch employee names and their daily records
$sql = "SELECT e.name, d.id AS day_id, d.day_of_month, d.status
FROM employees e
JOIN employee_days d ON e.id = d.employee_id
ORDER BY e.name, d.day_of_month";
$result = $conn->query($sql);
$currentEmployee = null;
?>
num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$name = htmlspecialchars($row['name']);
$day = htmlspecialchars($row['day_of_month']);
$status = htmlspecialchars($row['status']);
$dayId = htmlspecialchars($row['day_id']); // Unique ID for the day
// Start a new card for each employee
if ($currentEmployee !== $name) {
if ($currentEmployee !== null) {
// Close previous card
}
echo '
';
$currentEmployee = $name;
}
// Directly map the database status to button classes
$statusToClassMap = [
'v' => 'btn-primary', // Blue for 'v'
'x' => 'btn-light', // White for 'x'
'Off' => 'btn-danger' // Red for 'off'
];
// Get the badge class from the map, default to 'btn-secondary' if status is unknown
$badgeClass = $statusToClassMap[$status] ?? 'btn-danfer';
// Display button
echo '';
}
// Close the last card
echo '
';
} else {
echo '
No data available.
';
}
?>