Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Location
    UK, England
    Posts
    268
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Randomly Changing Pictured Links On Page

    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:

    Code:
    $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

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,371
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    Jimmy,

    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:
    http://www.webdesignforums.net/showthread.php?t=24175

    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •