View Full Version : Randomly Changing Pictured Links On Page

07-30-2006, 04:50 AM
How can I make pictures display randomly on my page, when clicked on, they take you to different links. They all should be display in the same cell of the table.

Ive just picked this up from somewhere, but I dont know how to implement it into my website. I have code, Im not sure if this is right, but maybe its something like this:

$random_number = rand(1, 5);

$random_banner[1] = '<a href="http://www.link1.com/"><img src="path/to/banner1.gif" alt="" border="0" /></a>';
$random_banner[2] = '<a href="http://www.link2.com/"><img src="path/to/banner2.gif" alt="" border="0" /></a>';
$random_banner[3] = '<a href="http://www.link3.com/"><img src="path/to/banner3.gif" alt="" border="0" /></a>';
$random_banner[4] = '<a href="http://www.link4.com/"><img src="path/to/banner4.gif" alt="" border="0" /></a>';
$random_banner[5] = '<a href="http://www.link5.com/"><img src="path/to/banner5.gif" alt="" border="0" /></a>';

The blue numbers represent the range of random numbers to be generated, or the number of banners you have in your rotation. You need to edit the top two numbers appropriately, and then create a $random_banner[X] line for each number in the range. In the above code, the random number is between 1 and 5, inclusive, and there are five banners defined.

Change the red code appropriately for each banner.

Could someone give me clearer insight in how to do this. Im not sure where to start :confused:

07-30-2006, 05:46 PM

You would use a server-side language such as PHP.

Using PHP would require you to change the extension of
the page you're using to .php (example... index.php instead of index.html).

See this link:

It explains two methods. One where you name your images
photo_1.jpg, photo_2.jpg, photo_3.jpg etc ...

Another method where it reads the images from a directory and
creates an array from that list.

The first method uses less bandwidth as the article describes.