0

I want to display a BLOB image from my MySQL db.

I already tried these solutions but I couldn't figure out how to use them in my code: Stack post

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM data ORDER BY data.id desc";
$result = $conn->query($sql) or die(mysqli_error($conn));//get query code error
$rows = $result->fetch_all(MYSQLI_ASSOC); //use fetch_all()
echo "<table class='table table-striped table-bordered'>
<tr>
<th>ID</th>
<th>date</th>
<th>security</th>
<th>photo</th>
</tr>"; // put table code outside

if ($result->num_rows > 0) {
    foreach($rows as $row) { //apply foreach()
        echo "<tr>
        <td>" . $row["id"]. "</td>
        <td>" . $row["Date"]."</td>
        <td>" . $row["Security"]. "</td>
        <td>" . $row["Photo"]. "</td>
    </tr>"; 
    }
} else {
    echo "No data found";
}
echo "</table>"; //close table outside
$conn->close();
?>

Can someone explain how to make it work? Or repost my code with the solution in it. I tried to insert this in my code but couldn't figure it out:

"<img src='data:image/jpeg;base64,' . base64_encode( $row['Photo'] ) . '' />";

We upload JPG files.

  • `echo "";` is it just syntax error, please check once? – Rahul Sep 13 '19 at 11:24
  • I tried to change the syntax of course, because this wouldn't work in my code. Once I had it working but outside the table. –  Sep 13 '19 at 11:26
  • And we can’t work with “doesn’t / wouldn’t work”, because that has nearly zero value as a problem description. Please go read [ask], and then give us something we can actually work with. Show us what you tried _inside_ of the context of your code. Check out the generated HTML code, is that what you expected it to be in the first place? And do you have proper PHP error reporting enabled to begin with? If not, do that first of all. – misorude Sep 13 '19 at 11:29
  • Please read: https://stackoverflow.com/questions/15318368/mysqli-or-die-does-it-have-to-die – Dharman Sep 13 '19 at 11:52
  • @misorude instead of saying that you could also redirect me to a post like [this](https://stackoverflow.com/questions/42624493/how-to-display-blob-image-in-td) I gave you my problem and what I tried. –  Sep 14 '19 at 13:41

1 Answers1

0

instead of

<td>" . $row["Photo"]. "</td>

Please use this

<td><img src='data:image/jpeg;base64," . base64_encode($row['Photo']) . "' /></td>
nbk
  • 45,398
  • 8
  • 30
  • 47
  • I already [found it](https://stackoverflow.com/questions/42624493/how-to-display-blob-image-in-td) but thank you very much for the answer. –  Sep 14 '19 at 13:40