2014-07-23 47 views
-2

我试图显示从php代码中获取的图像。下面是我的代码n =但它没有显示任何内容。有人请帮忙。是否有可能在PHP中包含css

<?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

+1

它不应该是这样:':URL' – Ghost

回答

0

您正在backgrount图像上使用图像标记。你只需要给出确切的图像路径。

$img_path = ''; // your image path 
<style> 
#small{ background-image:url("<?php echo $img_path ?>");} 
</style> 
+0

感谢所有,..其现在的工作( '路径/到/天等。') –

1

你用错误的语法为您的背景图片,所以它不会显示。

您应该使用例如:

#small{ background-image: url('yourimagename.jpg');} 

并且您设置了$profile_pic1 img标签。

你应该改变你的代码:

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

到:

$profile_pic1 = 'user/shail/'.$avatar1; 

和你的代码:

#small{ background-image:<?php echo $profile_pic1 ?>;} 

到:

#small{ background-image: url('<?php echo $profile_pic1 ?>'); } 
1

无需整个img标签添加到CSS,只是通过图像出现,

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

#small{ background-image:url('<?php echo $image?>' } 
1

什么你也几乎是有道理的,但是你的$profile_pic1被设置为一个HTML标签,而您需要根据CSS语法编写它,只要您继续将其写入样式标记中即可。

CSS Background - W3School

相关问题