Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying Multiple Images using PHP

Tags:

php

mysql

I need to show multiple images from a table in a database which has certain ID, but a broken image appears like this

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>Display multiple images from MySQL database in PHP</title>
</head>
<body>
  <?php
    $tag_id=111;

    $link = mysqli_connect("localhost", "root", "mysql", "hospital");
    $file_path = 'http://localhost/display-all-images.php';

    $sql = "SELECT * FROM `rays_analysis` WHERE id=$tag_id;";
    $mq = mysqli_query( $link, $sql) or die ("not working query");

    while ($all_images = $mq->fetch_assoc())
    {
      $image = htmlspecialchars(stripslashes($all_images["id"]));
      // $image = $all_images ['id'];

      echo '<img src="http://localhost/display-all-images.php/'.$image.'" width="360" height="150">';
    }
  ?>
</body>
</html>
like image 520
بسمة صلاح Avatar asked May 07 '26 17:05

بسمة صلاح


1 Answers

You need the proper path of your image

echo '<img src="http://localhost/display-all-images.php/'.$image.'" width="360" height="150">';

in Your code you find image inside the php file not in folder if your $image variable is like imagename.jpg and it store in images folder

Your syntax should be

echo '<img src="http://localhost/yourprojectname/images/'.$image.'" width="360" height="150">';
like image 64
Maninderpreet Singh Avatar answered May 09 '26 05:05

Maninderpreet Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!