Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random image and table color on the welcome screen?

Status
Not open for further replies.

SheilaAlighieri

Technical User
Nov 16, 2002
68
NL
Hi!

While I was surfing the web I ran into quite an interesting website, namely of Compagnie Financière Richemont S.A. ( The pictures on the welcome page change with each viewing. So does the color of the center table. I know there is some php involved. But I am not sure how it's done exactly. Check this script:

<script type=&quot;text/javascript&quot;>
var myimages=new Array()

function preloadimages(){
for (i=0;i<preloadimages.arguments.length;i++){
myimages=new Image()
myimages.src=preloadimages.arguments
}
}

preloadimages(&quot;../images/home/copyright_2002_richemont_home<? echo $iRandom ?>_thebrands_on.gif&quot;,&quot;../images/home/copyright_2002_richemont_home<?echo $iRandom?>_investorinfo_on.gif&quot;,&quot;../images/home/copyright_2002_richemont_home<?echo $iRandom?>_companyprofile_on.gif&quot;,&quot;../images/home/copyright_2002_richemont_home<?echo $iRandom?>_careers_on.gif&quot;,&quot;../images/home/copyright_2002_richemont_home<?echo $iRandom?>_contact_on.gif&quot;,&quot;../images/copyright_2002_richemont_arrow_on.gif&quot;)

function goUrl(Selected) {
var newURL = Selected.options[Selected.selectedIndex].value ;
if (newURL!=&quot; &quot;) {
document.location.href = newURL;
}
}
</script>

These codes should do it. But I don't know how to come to the side server scripting, which randomly picks certain images and which changes the tablecolor accordingly. Check the site to see what I mean.

I would greatly appreciate all help :) I want to use to such a script for a non-commercial website.

Sheila
 
load the images into an array and use the array_rand function
 
Sheila,

What they are doing here is using naming with a random integer number.
Their images are named 1_thebrands.gif etc. where the first number marks all images belonging to one set. The color change is inherent in the images, there's nothing to do.

So you need:
n sets of images named n_imagename.gif (or jpg, any format).
A function that productes the random number between 1 and n. The just print the number as they do in the example and you are all set.

Read about generating random numbers:
 
THanks guys :) I am sure I can work it out from here. If I run into trouble later on, I will get back to you (if I may :))

Sheila
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top