Notifications

Records
connect_error) { die("Connection failed: " . $conn->connect_error); } // Query for rows with processed = 2 $sql = "SELECT * FROM notifications"; $result = $conn->query($sql); $all_notifications = []; if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $all_notifications[] = $row; } } $user_id = $_SESSION['iduserlogin']; $all_notification_ids = array_column($all_notifications, 'id'); $all_notification_ids_str = implode(',', $all_notification_ids); $sql = "SELECT notification_id FROM seen_notifications WHERE notification_id IN ($all_notification_ids_str) AND user_id = $user_id"; $result = $conn->query($sql); $seen_notification_ids = []; if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $seen_notification_ids[] = $row['notification_id']; } } $seen_notifications = []; foreach($all_notifications as $notification){ if(in_array($notification['id'], $seen_notification_ids)){ $seen_notifications[] = $notification; } } $unseen_notifications = array_udiff($all_notifications, $seen_notifications, function ($a, $b) { return $a['id'] <=> $b['id']; }); // unseen notifications with mark as seen button and different color , seen without that if(!empty($all_notifications)){ foreach($all_notifications as $notification){ if(in_array($notification, $unseen_notifications)){ echo ""; }else{ echo ""; } echo ""; echo ""; echo ""; if(in_array($notification, $unseen_notifications)){ echo ""; }else{ echo ""; } echo ""; } } $conn->close(); ?>
ID Title Description Actions
" . $notification['id'] . "" . $notification['title'] . "" . $notification['description'] . "