mysqli获取数组从图像中获取所选id的所有数据

I am storing product data in my database including the image file. I then display all of my products in one page through a foreach loop. If I click on a product it takes me to a page called viewProducts.php . In that page, I pull the information from that ID and show it on that page in more detail. However, for some reason the image file is not changing to that ID's image. The image stays as the first product ID's. All of the other product data is correct and correlates with the product I clicked on to view.

My code for the viewProducts page to show the data is this..

<?php
    $result = mysqli_query($con,"SELECT * FROM products");
        if($row = mysqli_fetch_array($result)) {
            $products[$row['product_id']] = $row;

                echo "<img class='sizedimg' src='productpics/".$row['img'] ."' alt='Product Pic'>";
        }
?>

If it makes it easier to view, my site is buyfarbest.com . Go to the products page and then click on the first product to see it is correct and then click on any of the others.

Products foreach loop

<?php   
// Loop to display all products


foreach($products as $id => $product) {
?>
                    <div class="item">
                        <div class="productpiccontainer">
                                <?php echo "<img class='sizedimg' src='productpics/".$product['img'] ."' alt='Product Pic'>"; ?>
                        </div>      

                                <p><?php echo "<a href='./viewProduct.php?view_product=$id'>" . $product['product_name'] . "</a>"; ?></p>
                                <p> <?php echo "$" . $product['price']; ?> </p>                                     
                    </div>
<?php
    }
?>

Change your viewProduct.php

if your id is interger do it like this

$result = mysqli_query($con,"SELECT * FROM products where product_id =".$_GET['view_product']);

if your id is not integer to it like this

$result = mysqli_query($con,"SELECT * FROM products where product_id ='".$_GET['view_product']."' ");