Jump to content

random background image


mistertylersmith

Recommended Posts

PHP 5

MYSQL 5

Firefox

 

the problem is that I'm trying to get one of three random images to be the background image for index.php.  I can get the images to display correctly, but they scroll with the page even though i specifically have it set not to do that.  Here is the code I'm using:

 

<?php
$file = array('pictures/misc/purplecrest_big2.png', 'pictures/misc/lion_clear3.png', 'pictures/misc/moto1.png');
$a = rand(0,2);
?>
<body style="background-image: url(<?php echo $file[$a]; ?>);
background-repeat: no-repeat;
background-attachment:fixed;
background-position: 90% 250px;
">

Link to comment
https://forums.phpfreaks.com/topic/100410-random-background-image/
Share on other sites

<?php
//Name your files pictures/misc/background1.png, pictures/misc/background2.png, and pictures/misc/background3.png
$file = "pictures/misc/background";
$extension = ".png";
$a = rand(0,2);
?>
<body style="background-image: url("<?php echo $file.''.$a.''.$extension; ?>");
background-repeat: no-repeat;
background-attachment:fixed;
background-position: 90% 250px;
">
<?php //This should work maybe? ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.