是否可以在php中包含css

是否可以在php中包含css,php,css,Php,Css,我试图显示从php代码获得的图像。下面是我的代码n=但它没有显示任何内容。有人请帮忙 <?php $db_conx=mysqli_connect("localhost","root","sultan","slide"); $sql = "SELECT * FROM photo WHERE username='shail' LIMIT 1"; $user_query = mysqli_query($db_conx, $sql); // Fetch the user row from the

我试图显示从php代码获得的图像。下面是我的代码n=但它没有显示任何内容。有人请帮忙

<?php

$db_conx=mysqli_connect("localhost","root","sultan","slide");
$sql = "SELECT * FROM photo WHERE username='shail' LIMIT 1";
$user_query = mysqli_query($db_conx, $sql);
// Fetch the user row from the query above
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
    $profile_id = $row["id"];
    $avatar1 = $row["avatar1"];

}
$profile_pic1 = '<img src="user/shail/'.$avatar1.'" width="100" height="80" >';

?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
#small{ background-image:<?php echo $profile_pic1 ?>;}
</style>

</head>
<body>
  <div id="small"></div>
 </body>
</html>

#小{背景图像:;}
谢谢
Shail

您对背景图像使用了错误的语法,因此无法显示

例如,您应该使用:

#small{ background-image: url('yourimagename.jpg');}
然后设置
$profile\u pic1
img标签

您应该更改代码:

 $profile_pic1 = '<img src="user/shail/'.$avatar1.'" width="100" height="80" >';
#small{ background-image:<?php echo $profile_pic1 ?>;}
以及您的代码:

 $profile_pic1 = '<img src="user/shail/'.$avatar1.'" width="100" height="80" >';
#small{ background-image:<?php echo $profile_pic1 ?>;}
#小{背景图像:;}
进入:

#小{背景图片:url(“”)}

您正在背景图像上使用图像标记。您只需给出确切的图像路径即可

$img_path = ''; // your image path
<style>
#small{ background-image:url("<?php echo $img_path ?>");}
</style>
$img_路径=“”;//您的图像路径
#小{背景图像:url(“”;}

无需将整个img标签添加到css中,只需将图像传递到那里

 $image=  'user/shail/'.$avatar1; //Image

 #small{ background-image:url('<?php echo $image?>' }
$image='user/shail/'。$avatar1//形象
#小{背景图像:url(''}

您所做的几乎是有意义的,但是您的
$profile_pic1
设置为HTML标记,而您需要根据CSS语法编写它,前提是您继续在样式标记中编写它


它不应该是这样的:
:url('path/to/government等')