i have a small problem with my code. I'm trying to show an image out of my database on my homepage using php (pdo). Problem is: I don't really know how to let insert the variable of the image in the HTML img tag. Where is my mistake / How can I fix it?
I am saving the images in my mysql database as a blob (largeblob) and all images are .jpg and / or .png
<?php
$db = new Dbh;
$pdo = $db->connect();
$counter = 0;
$content = "";
$statement = $pdo->prepare('SELECT * FROM images');
$statement->execute();
while ($row = $statement->fetch()) { ?>
<img src = "<?php echo $row['image']; ?>">
<?php }
?>
The thing happening right now is, is that html just shows some kind of bit code full of strange symbols
Thanks for your help in advance!
echo '<img src="data:image/jpeg;base64,'.base64_encode($row['image']).'"/>';srcattribute isn't going to work as is. Here is a way to use javascript to render blob images: stackoverflow.com/questions/7650587/…. Note that usingidas a selector as this example will not work in a loop structure, so you may want to use a class instead, and dynamically set a class identifier that increments each loop iteration (e.g.,$classname = 'myimage-' . $i++;)