3

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>
1

1 Answer 1

4

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">';
Sign up to request clarification or add additional context in comments.

2 Comments

what is $image variable returning ? can u echo it .
i changed the code by completely another one and it works :) thanks alot for ur help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.