php - mysqli fetch array grabbing all data from chosen id except for the image -
i storing product data in database including image file. display of products in 1 page through foreach loop. if click on product takes me page called viewproducts.php . in page, pull information id , show on page in more detail. however, reason image file not changing id's image. image stays first product id's. of other product data correct , correlates product clicked on view.
my code viewproducts page show data this..
<?php $result = mysqli_query($con,"select * products"); if($row = mysqli_fetch_array($result)) { $products[$row['product_id']] = $row; echo "<img class='sizedimg' src='productpics/".$row['img'] ."' alt='product pic'>"; } ?> if makes easier view, site buyfarbest.com . go products page , click on first product see correct , click on of others.
products foreach loop
<?php // loop display products foreach($products $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 viewproduct.php
if id interger this
$result = mysqli_query($con,"select * products product_id =".$_get['view_product']); if id not integer this
$result = mysqli_query($con,"select * products product_id ='".$_get['view_product']."' ");
Comments
Post a Comment