Reputation: 95
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
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