index.php 中的内联样式不显示从数据库中提取的背景图像

Inline style in index.php does not display background image pulled from database

我有一个 index.php,我已经成功地填充了 mysql 数据库中相关表的内容。但是,有一个部分(事件)具有在 css 中定义的背景图像。然而,在将 css 更改为 php 并确保提及 <?php header("Content-type: text/css; charset: UTF-8"); ?> 之后,background-image:url:"<?php echo $eventsrow[0]['filepath'];?>" 除了不显示图像外,整个文档的样式都乱七八糟.

所以我决定将图像调用放在 index.php 中,就像我对其他部分所做的那样,使用内联样式:<div class="monthevent" style="background-image:url("<?php echo $eventsrow[0]['filepath'];?>");">

然而图像根本没有出现。这有什么问题吗?会很感激任何光。上述变量的 var_dump 给出了正确的值:即。文件路径,但不显示图像;我也尝试调整相对于 css 的路径(以防万一),但没有出现图像。如果您对问题可能是什么有任何想法,将不胜感激?

你必须这样使用:

<div class="monthevent" style="background-image:url('<?php echo $eventsrow[0]['filepath'];?>');">

不是url里面的双引号,用单引号来区分url!

如果使用双引号:

<div class="monthevent" style="background-image:url("your_url.com");">
</div>

如果使用单引号:

<div class="monthevent" style="background-image:url('your_url.com');">
</div>