0

I have working from code here on stackoverflow retrieval of Image blobs from a mysql database using PHP. My question now is how do I show multiple image blobs in different div's from a mysql database. here is my current code. Any help would be appreciated.

<?php
$id ='1';
$db = mysqli_connect("localhost","brianrob_usr","","brianrob_productdb"); //keep your db name
$sql = "SELECT * FROM Products WHERE id = $id";
$sth = $db->query($sql);
$result=mysqli_fetch_array($sth);
echo '<img src="data:image/jpeg;base64,'.base64_encode( $result['Image'] ).'"/>';

?>
  • 1
    Possible duplicate of [How to retrieve images from MySQL database and display in an html tag](https://stackoverflow.com/questions/7793009/how-to-retrieve-images-from-mysql-database-and-display-in-an-html-tag) – icecub Jul 21 '17 at 23:16
  • While that is going in the right direction, That is not exactly what I want to do. I want to pull each image from the blob in each row and then display them in a div. I want to pull the ID automatically, not enter it each time. –  Jul 21 '17 at 23:19
  • Don't just read the accepted anwer. There are other answers as well. One telling you how to loop through the array and show each image :) – icecub Jul 21 '17 at 23:22

1 Answers1

0

Just use loop, and do action for each row in MySQL:

 <?php
    $id ='1';
    $db = mysqli_connect("localhost","brianrob_usr","","brianrob_productdb"); //keep your db name
    $sql = "SELECT * FROM Products WHERE id = $id";
    $sth = $db->query($sql);
    while($row = $sth->fetch_array()){
    echo '<div><img src="data:image/jpeg;base64,'.base64_encode( $row['Image'] ).'"/></div>';
    }
    ?>
Djordje Vujicic
  • 414
  • 5
  • 20