Acc Settings
connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Update the status of notifications to 'read' if the request comes from the AJAX call
if (isset($_POST['mark_read'])) {
$sql = "UPDATE notifications SET status = 'read' WHERE status = 'unread'";
$conn->query($sql);
exit;
}
$notificationCount = 0;
$notifications = [];
// Query to count unread notifications
$sql = "SELECT COUNT(*) AS count FROM notifications WHERE status = 'unread'";
$result = $conn->query($sql);
if ($result) {
$row = $result->fetch_assoc();
$notificationCount = $row['count'];
}
// Query to fetch all notifications
$sql = "SELECT message, created_at FROM notifications ORDER BY created_at DESC";
$result = $conn->query($sql);
if ($result) {
while ($row = $result->fetch_assoc()) {
$notifications[] = $row;
}
}
$conn->close();
?>