<?php
// Database connection
include("includes/db.php");

// Check if the message ID is set in the URL
if (isset($_GET['id'])) {
    $message_id = intval($_GET['id']); // Get the message ID and sanitize it

    // Fetch the images associated with the message ID
    $query = "SELECT image_path FROM support_images WHERE message_id = ?";
    $stmt = $conn->prepare($query);
    $stmt->bind_param('i', $message_id); // 'i' for integer
    $stmt->execute();
    $result = $stmt->get_result();

    // Check if there are images
    if ($result->num_rows > 0) {
        echo "<div class='image-container'>";

        // Loop through and display each image
        while ($row = $result->fetch_assoc()) {
            $image_path = htmlspecialchars($row['image_path'], ENT_QUOTES, 'UTF-8'); // Sanitize the image path
            echo "<img src='uploads/support/$image_path' alt='Support Image' class='img-thumbnail' style='max-height: 250px; max-width: 250px; object-fit: cover;' />";
        }

        echo "</div>";
    } else {
        echo "<div class='alert alert-warning text-center'>No images found for this message.</div>";
    }
} else {
    echo "<div class='alert alert-danger text-center'>Invalid message ID.</div>";
}

// Close the database connection
$conn->close();
?>
