Reputation:
Hi I have a working code that pulls image blobs from the MYSQL database, However I want to in addtion make them click able so people can click to a product page. This is my working code so far I just haven't been able to add a Url to make the image clickable. How would I do this?
<?php
$id ='1';
$db = mysqli_connect("localhost","brianrob_usr","","brianrob_productdb"); //keep your db name
$sql = "SELECT * FROM Products WHERE id = $id";
$sth = $db->query($sql);
while($row = $sth->fetch_array()){
echo '<div><img src="data:image/jpeg;base64,'.base64_encode( $row['Image'] ).'"/></div>';
}
?>
Upvotes: 0
Views: 165
Reputation: 589
You need to add an anchor tag around the image.
echo '<div><a href="'.$row['URL'].'"><img src="data:image/jpeg;base64,'.base64_encode( $row['Image'] ).'"/></a></div>';
should do the trick presuming you have the URL as a column in the DB.
Upvotes: 1
Reputation: 3260
Try this:
echo '<div><img href="someurl.com" src="data:image/jpeg;base64,'.base64_encode( $row['Image'] ).'"/></div>';
Or, if it's dynamic and you have an image name in a field, do this:
echo '<div><img href="' . $row["imageName"] . '" src="data:image/jpeg;base64,'.base64_encode( $row['Image'] ).'"/></div>';
Upvotes: 0