我使用php从数据库中检索图像然后我想用CCD_ 1中的这个图像作为背景。
我试着使用这个代码,但它不起作用:
<div class="fill" style="background-image:url('<?php echo "<img src='getImg.php?id=$13'>"; ?>');"></div>
Rajdeep Paul是正确的,变量也是无效的
css的语法不正确:
<div class="fill" style="background-image:url('<?php echo "getImg.php?id=$X13" ?>')"></div>
没有<img src
。。。
您的background-image:url
语法和variable
名称不正确,请尝试以下操作:
<?php
echo "<div class='fill' style="background-image:url('getImg.php?id=$VALIDVARIABLE')"></div>";
PHP变量规则:
- 变量以
$
符号开头,后跟变量 - 变量名必须以字母或下划线字符开头
- 变量名不能以数字开头
- 变量名只能包含字母数字字符和下划线(
A-z
、0-9
和_
) - 变量名区分大小写(
$age
和html
0是两个不同的变量)
试试这个:
<?php $url = require("path/to/getImg.php?id=".$13;); ?>
<div class="fill" style="background-image:url('<?php echo $url; ?>');"></div>
我不确定这条线:
<?php $url = require("path/to/getImg.php?id=".$13;); ?>
但是你需要在背景图像上使用的值:url("ything")不是img标记。。。当然你需要把url放到图片上。
我希望它能帮助你。