how to fetch image from database in php and display in table?

how to fetch image from database in php and display in table : Firstly, create a connection to the MySQL database. and fetch image from folder in PHP and display in table.

how to fetch image from database in php and display in table?

Fetching image from MySQL database in PHP as well as display in HTML table is Like to fetch any data from database and show in HTML Table.

To fetch image from url we use HTML tag <img src =""> as below

<img src="$row['image_name'].' width="100px" height="100px">

Step 1: Connection with Database

The config.php file is used to connect with the database. Firstly, make a connection to the MySQL database.
config.php

<?php

$link = mysqli_connect("localhost","root","","pakainfo_v1");  // Live database connection

if(!$link)
{
    die("Connection failed: " . mysqli_connect_error());
}

?>

Don’t Miss : How to retrieve image from database in php?

Read Also:  php array remove keys keep values example

Step 2: Fetching image from Database Code

index.php

<!DOCTYPE html>
<html>
<head>
  <title>Fetch image from database in PHP</title>
</head>
<body>

<h2>All Records</h2>

<table border="2">
  <tr>
    <td>Rank.</td>
    <td>Member Name</td>
    <td>Profile DP</td>
  </tr>

<?php

include "config.php"; // Using database connection file here

$records = mysqli_query($link,"select * from members"); // fetch data from database

while($data = mysqli_fetch_array($records))
{
?>
  <tr>
    <td><?php echo $data['id']; ?></td>
    <td><?php echo $data['m_name']; ?></td>
    <td><img src="<?php echo $data['profile_img']; ?>" width="100" height="100"></td>
  </tr>	
<?php
}
?>

</table>

<?php mysqli_close($link);  // close connection ?>

</body>
</html>

Don’t Miss How to fetch image from database in PHP and display?

I hope you get an idea about how to fetch image from database in php and display in table?.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.