0

I would like to derive my website background image from database.those background images are loading through banner.css file.

banner.css 

<?
header("Content-type: text/css");  
include("getfrontimage.php");
$theme = "images";
$size = "cover";
$height = "780px";

?>
<style>
.w3layouts-banner-top{
    background: url(<?php  echo $theme.'/'.$row1[image];?>) no-repeat 0px 0px;
    background-size: <?php echo $size; ?>;
    -webkit-background-size: <?php echo  $size; ?>;
    -moz-background-size: <?php echo $size; ?>;
    -o-background-size: <?php echo $size; ?>;     
    -moz-background-size: <?php echo $size; ?>;
    min-height: <?php echo $height; ?>;
}
.w3layouts-banner-top1{ 
    background: url(<?php echo  $theme.'/'.$row2[image]; ?>) no-repeat 0px 0px;
    background-size: <?php echo $size; ?>;
    -webkit-background-size: <?php echo $size; ?>;
    -moz-background-size: <?php echo $size; ?>;
    -o-background-size: <?php echo $size; ?>;     
    -moz-background-size: <?php echo $size; ?>;
    min-height: <?php echo   $height; ?>;
}
.w3layouts-banner-top2{
    background: url(<?php echo $theme.'/'.$row3[image]; ?>) no-repeat 0px 0px;
    background-size: <?php echo $size; ?>;
    -webkit-background-size: <?php echo $size; ?>;
    -moz-background-size: <?php echo $size; ?>;
    -o-background-size: <?php echo $size; ?>;     
    -moz-background-size: <?php echo $size; ?>;   
    min-height: <?php echo $height; ?>;
}
</style>

But background images are not loading in my website. I refer this links enter link description here

please give me any idea to resolve this problem.

Rainbow
  • 6,772
  • 3
  • 11
  • 28
Arebhy Sridaran
  • 586
  • 12
  • 28

1 Answers1

2

$row1[image] must be $row1['image'], because the array key can either be an integer or a string. If you enable display of warnings, you'll get a message in this case: Warning: Use of undefined constant image Correct the other variables.

Processing PHP code in files with the .css extension is not a not quite optimal solution, because you need to add special directives so that your web server processes css files as php files. It is easier to include CSS rules in a php file, and then add the css file to a web page using:

<link rel="stylesheet" href="css/styles.php">

By the way, short tags <?= $size ?> are more readable than <?php echo $size; ?>.

camelsWriteInCamelCase
  • 1,655
  • 1
  • 10
  • 15