...

View Full Version : 3 random image/links on same page... no repeats



thewillum
04-25-2006, 07:04 PM
I need to create a series of three random thumbnail images on a page w/ every reload.

But none of the 3 can be repeats of the other two images.

Anyone know a code for this? I know how to do random images, but I don't know how to ensure that there are no repeats.

Thank you
William

roxii
04-25-2006, 07:10 PM
Using PHP with mySQL is generally a better solution than using JavaScript for this type of thing.

If you absolutely have to use JavaScript, you can run the random image/text chosen through a for loop to make sure it doesn't match the others. There are a lot of scripts out there premade for you, just do a quick Google search and you'll find something.

felgall
04-25-2006, 10:37 PM
Javascript solution (no loops required):



var imgArray = ['img1.gif','img2.gif','img3.gif', ......'img100.gif'];
function randOrd(){return (Math.round(Math.random())-0.5); }
imgArray.sort(randOrd);
var pic1 = imgArray[0]; // first random image
var pic2 = imgArray[1]; // second random image
var pic3 = imgArray[2]; // third random image


Still better done on the server though if you can.

thewillum
04-26-2006, 02:58 AM
Thanks alot, that'll work great...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum