prepare(" SELECT c.*, u.username, u.avatar_url, (SELECT COUNT(*) FROM reactions WHERE comment_id = c.id AND reaction_type = 'thumb') as thumbs, (SELECT COUNT(*) FROM reactions WHERE comment_id = c.id AND reaction_type = 'heart') as hearts, (SELECT COUNT(*) FROM reactions WHERE comment_id = c.id AND reaction_type = 'pray') as prays, (SELECT COUNT(*) FROM reactions WHERE comment_id = c.id AND reaction_type = 'insight') as insights, (SELECT COUNT(*) FROM reactions WHERE comment_id = c.id AND reaction_type = 'clap') as claps FROM comments c JOIN users u ON c.user_id = u.id WHERE c.video_id = ? ORDER BY c.created_at DESC "); $stmt->execute([$video_id]); $comments = $stmt->fetchAll(); // Format dates for display foreach ($comments as &$c) { $c['display_date'] = date('M d, Y', strtotime($c['created_at'])); } echo json_encode($comments); } catch (Exception $e) { echo json_encode([]); } ?>