Page 1 of 1
Random image on refresh
Posted: Wed Dec 09, 2009 10:42 am
by brunko
Hi, everybody.
Got a problem with a specific thing. I got lost when trying to make simple header image rotating with 2 other images after refresh.
Want to have different image in header after refreshing a browser and should be linkable as well.
here is the code I need to modify:
$style_td = ' style="background-image: url(\''.$setting['shop']['url'].'img/blue.jpg\')"';
Thanx for help.
Re: Random image on refresh
Posted: Wed Dec 09, 2009 11:19 am
by rufee
I would use a random number for that
Code: Select all
$img = rand(1, 3);
$style_td = ' style="background-image: url(\''.$setting['shop']['url'].'img/$img.jpg\')"';
this will randomly display an image
images names have to be 1.jpg, 2.jpg and so on
if you want to display images in an order like 1, 2, 3 then use sessions
Re: Random image on refresh
Posted: Wed Dec 09, 2009 12:04 pm
by brunko
I tried it but got
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING...
message...
Re: Random image on refresh
Posted: Wed Dec 09, 2009 12:21 pm
by rufee
$img = rand(1, 3);
$style_td = ' style="background-image: url(\''.$setting['shop']['url'].'img/$img.jpg\')"';
oh the code tags displayed the code wrong
Re: Random image on refresh
Posted: Wed Dec 09, 2009 12:38 pm
by brunko
I am neither
but ...I figured out that there is one php file called style.php and there is code for this pictures:
Code: Select all
.logotd{
background: #fff url('img/3.jpg') no-repeat;
width: 557px;
height: 135px;
vertical-align: top;
}
where 3.jpg is one of the pictures wanted to be shown. Shouldn,t there be $img.jpg as well???
Re: Random image on refresh
Posted: Wed Dec 09, 2009 12:43 pm
by rufee
this is a style for use in html <class="logotd"/>
its for something else in your page
EDIT: alright figured it out this should work
$img = rand(1, 3);
$style_td = ' style="background-image: url(\''.$setting['shop']['url'].'img/'.$img.'.jpg\')"';
Re: Random image on refresh
Posted: Wed Dec 09, 2009 12:58 pm
by brunko
but when I want to change picture manualy I have to overwrite it with the same number I used in previous code....otherwise it wont change