fetch image from mysqli in php code example
Example 1: how to retrieve image from database in php mysqli
$conn = mysqli_connect("localhost", "root", "", "student");
$img = mysqli_query($conn, "SELECT * FROM student_table");
while ($row = mysqli_fetch_array($img)) {
echo "<img src='images/".$row['imagename']."' >";
}
Example 2: display image from mysqli database
<?php ?>
<?php if($result->num_rows > 0){ ?> <div class="gallery"> <?php while($row = $result->fetch_assoc()){ ?> <img src="data:image/jpg;charset=utf8;base64,<?php echo base64_encode($row['image']); ?>" /> <?php } ?> </div> <?php }else{ ?> <p class="status error">Image(s) not found...</p> <?php } ?>