我有一个php脚本,其中包含div
html标记。并且我想将MySql中的css background-image
设置为每个div。
我的错误代码:
<?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();
?>
答案 0 :(得分:2)
尝试
<?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();
?>