Reputation:
I would like to know how to display multiples images from MySQL in Html.
I have two files: photogallery.php where I display the image and gallery.php where I have the php code. This works but I can only display 1 image and I can't see all images!
Here is the code for photogallery.php where I display the photo:
<div align='left'>
<img src='gallery.php' height='95' width='95'/>
</div>
and here is the code for gallery.php:
session_start();
$host = "localhost";
$username = "root";
$password = "";
$db_name = "photos";
$tbl_name="gallery";
mysql_connect("$host","$username","$password")or die ("error22");
mysql_select_db("$db_name") or die("error2");
$ussername=$_SESSION['username'];
$query= mysql_query("SELECT * FROM $tbl_name where username='$ussername'");
while($row= mysql_fetch_assoc($query)){
$imageData=$row["image"];
//header("content-type:image/jpeg");
echo $imageData;
}
Thank you!
Upvotes: 0
Views: 104
Reputation: 831
If you have image data stored on the database with a function like get_file_contents :
while($row= mysql_fetch_assoc($query)){
$imageData=$row["image"];
echo "<div align='left'>";
echo " <img src='data:image/jpeg;base64,"
. base64_encode($imageData) . "' height='95' width='95'/>";
echo "</div>";
}
Upvotes: 1
Reputation: 737
if we assume that $row["image"]
is path to image, then you should change your code like below:
...
while($row= mysql_fetch_assoc($query)){
$imageData=$row["image"];
?>
<div align='left'>
<img src='<?php echo $imageData;?>' height='95' width='95'/>
</div>
<?php
}
...
I don't execute my code, I want show you only idea
Upvotes: 0