بسمة صلاح
بسمة صلاح

Reputation: 95

Displaying Multiple Images using PHP

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>

Upvotes: 3

Views: 2466

Answers (1)

Maninderpreet Singh
Maninderpreet Singh

Reputation: 2587

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">';

Upvotes: 4

Related Questions