What is the best way to display an image in a new window after clicking on a field in a PHP-generated table?

To display an image in a new window after clicking on a field in a PHP-generated table, you can use JavaScript to open a new window with the image when the field is clicked. You can pass the image URL as a parameter to the JavaScript function. This way, when a user clicks on the field, a new window will open displaying the image.

<?php
// PHP code to generate a table with image fields
echo "<table>";
foreach ($images as $image) {
    echo "<tr>";
    echo "<td><a href='#' onclick='displayImage(\"$image\")'>View Image</a></td>";
    echo "</tr>";
}
echo "</table>";
?>

<script>
function displayImage(imageUrl) {
    window.open(imageUrl, '_blank');
}
</script>