2

I have a php script, which contain div html tag. and I want to set css background-image from MySql to each divs.

My Wrong Code:

<?php
require 'config.php';
$query = "SELECT * FROM `users`";
$result = mysqli_query($conn, $query);
while($row = mysqli_fetch_array($result))
{
    $user_Image = $row['blob'];
    echo "<div class='avatar' style='background-image :url(\"data:image/jpeg;base64, base64_encode($user_Image)\");'></div>";
}
$conn->close();
?>

1 Answer 1

2

try this

      <?php
require 'config.php';
$query = "SELECT * FROM `users`";
$result = mysqli_query($conn, $query);
while($row = mysqli_fetch_array($result))
{
    $user_Image = $row['blob'];
    ?>
    <div class="avatar" style="background-image :url(data:image/jpeg;base64, base64_encode(<?php echo $user_Image;?>)")></div>
<?php     
}
$conn->close();
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Sir, your answer probably right to me, but now i want to save my blob image into a new record which is also blob, please how can i do this. thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.