1
0 Comments

HOW TO DISPLAY IMAGES ON A WEBSITE FROM DATABASE USING PHP

You do not need to store the images in a database, this is because image files are large and they can easily fill the database.

Instead, you store the images in a folder on your server, and save the image names in the database.

If you want to display images on your website, you use this php code:

while ($row = mysqli_fetch_array($result1))
{
echo '<img src="imageFolder/'.$row['image'].'"/>';

}//end while

EXPLANATION

  1. while ($row = mysqli_fetch_array($result1))

The 'while' loop runs through the database to identify names of images. Any image name identified is stored in variable $row.

  1. echo '<img src="imageFolder/'.$row['image'].'"/>';

You echo(display) the image on your website. The 'imageFolder' refers to the folder that holds all your images and $row['image']
compares the image name in $row with the image names in the imageFolder.

If a match is found in the imageFolder, that image is displayed on the website.

on July 29, 2023