Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   Help With Simple Rotation Script? (https://www.warriorforum.com/programming/203304-help-simple-rotation-script.html)

Scott Murdaugh 18th April 2010 08:23 PM

Help With Simple Rotation Script?
 
Hey guys,

I've Googled, not much of a programmer.

I'm looking for a simple PHP or javascript code that I can place on a site to rotate one image 25% of the time and the second 75% of the time.

I would assume this is just a few simple lines of code, maybe I'm wrong.

Any links to something like this or ideas?

Thanks in advance!

-Scott

theIMgeek 18th April 2010 08:40 PM

Re: Help With Simple Rotation Script?
 
The following is based on randomization, which means it is not at all guaranteed to be 25% and 75% in the short term. But over time the 1-in-4 odds will even out.

$random_images = array();
$random_images[] = 'imageA.jpg';
$random_images[] = 'imageA.jpg';
$random_images[] = 'imageA.jpg';
$random_images[] = 'imageB.jpg'; // this is the ~25% file name

shuffle($random_images); // randomize the order of the above files

echo '<img src="path/to/images/'.$random_images[0].'" />'; // print out the first random one


-Ryan

Scott Murdaugh 18th April 2010 09:11 PM

Re: Help With Simple Rotation Script?
 
Sweet! Thanks Ryan.

Going to try it out now.

-Scott

HomeBizNizz 19th April 2010 10:02 AM

Re: Help With Simple Rotation Script?
 
http://www.phpjunkyard.com/dnl/rantex10.zip


All times are GMT -6. The time now is 10:27 PM.