Rotating Images

Discussion in 'HTML & Website Design' started by Toonces51, Oct 30, 2005.

  1. #1
    I'm wondering if anyone has any experience with rotating a couple of different images in the same spot, with the same link (basically rotating between 2-3 different logos) each time the page is loaded.

    I've seen a java script out there for rotating ads, but I couldn't get it to work for some reason, and I've seen one that flips through pictures at a time interval, but not just when the page refreshes.

    Thanks.

    Toonces51
     
    Toonces51, Oct 30, 2005 IP
  2. mattmdesign

    mattmdesign Well-Known Member

    Messages:
    1,201
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    118
    #2
    Here is what I use, it is in PHP. Just replace those iframe's with your images, save the file as filename.php then in the page that you want it to appear put <? include("filename.php") ?>

    here is the code to put in filename.php:

    <?
    $codes = array(
    "<iframe src=\"http://rcm.amazon.com/e/cm?t=mattmartigrap-20&o=1&p=8&l=as1&asins=6304474350&fc1=000000&=1&lc1=0000ff&bc1=000000&lt1=_blank&IS2=1&f=ifr&bg1=ffffff&f=ifr\" width=\"120\" height=\"240\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\">
    </iframe>",
    "<iframe src=\"http://rcm.amazon.com/e/cm?t=mattmartigrap-20&o=1&p=8&l=as1&asins=0816039259&fc1=000000&=1&lc1=0000ff&bc1=000000&lt1=_blank&IS2=1&f=ifr&bg1=ffffff&f=ifr\" width=\"120\" height=\"240\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\">
    </iframe>",
    "<iframe src=\"http://rcm.amazon.com/e/cm?t=mattmartigrap-20&o=1&p=8&l=as1&asins=B00005MOYU&fc1=000000&=1&lc1=0000ff&bc1=000000&lt1=_blank&IS2=1&f=ifr&bg1=ffffff&f=ifr\" width=\"120\" height=\"240\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\">
    </iframe>",
    "<iframe src=\"http://rcm.amazon.com/e/cm?t=mattmartigrap-20&o=1&p=8&l=as1&asins=B000000JU9&fc1=000000&=1&lc1=0000ff&bc1=000000&lt1=_blank&IS2=1&f=ifr&bg1=ffffff&f=ifr\" width=\"120\" height=\"240\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\">
    </iframe>",
    "<iframe src=\"http://rcm.amazon.com/e/cm?t=mattmartigrap-20&o=1&p=8&l=as1&asins=B0007NE894&fc1=000000&=1&lc1=0000ff&bc1=000000&lt1=_blank&IS2=1&f=ifr&bg1=ffffff&f=ifr\" width=\"120\" height=\"240\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\">
    </iframe>"
    );

    shuffle($codes);
    $i=0;
    $number=1; while(list(, $code) = each($codes)) {
    if ($i>=$number) { break; }
    echo "$code";
    echo '<br>';
    $i++;
    }
    ?>
     
    mattmdesign, Oct 30, 2005 IP
    Colleen likes this.
  3. jazzylee77

    jazzylee77 Peon

    Messages:
    578
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Cool! I could use this for OW! ...uh I could change this a little and HEY!! This is similar to a random quote I use on ooof!! Quit kicking me man!!!
     
    jazzylee77, Oct 30, 2005 IP
  4. Colleen

    Colleen Illustrious Member

    Messages:
    6,777
    Likes Received:
    725
    Best Answers:
    1
    Trophy Points:
    430
    #4
    Interesting way of doing it. Thanks for the code! :) Sent you some green.
     
    Colleen, Oct 31, 2005 IP
  5. Roman

    Roman Buffalo Tamerâ„¢

    Messages:
    6,217
    Likes Received:
    592
    Best Answers:
    0
    Trophy Points:
    310
    #5
    I use this and it works very well:

    <script language="JavaScript">
    
    images = new Array(3);
    
    images[0] = "<a href = 'xxxxx'><img src='xxxx1.jpg' alt='xxxx'><br><b>text if needed</a>";
    images[1] = "<a href = 'xxxxx'><img src='xxxx2.jpg' alt='xxxx'><br><b>text if needed</a>";
    images[2] = "<a href = 'xxxxx'><img src='xxxx3.jpg' alt='xxxx'><br><b>text if needed</a>";
    
    
    index = Math.floor(Math.random() * images.length);
    
    document.write("<DL>\n");
    
    document.write("<DT>" + "" + images[index] + "\n");
    
    document.write("</DL>\n");
    
    </script>
    Code (markup):

    You can add unlimited pictures to rotate, but don't forget to change the newarray(x) value.
     
    Roman, Oct 31, 2005 IP
  6. Toonces51

    Toonces51 !@#$%^&*^%#@#$%

    Messages:
    107
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #6
    Thanks to both mattmdesign and roman1 for their help. I ended up using the Javascript just because I'm a little more familiar with that--I might try out the PHP version at some point too (seems to me I'll have plenty of uses for this code).

    Toonces51
     
    Toonces51, Oct 31, 2005 IP
  7. duenna

    duenna Peon

    Messages:
    104
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If it is only a three logo's would it not be a simpler idea to create an animated gif?

    That way if you minimalise the amount of code in the document?

    The PHP technique is great, try and remember to use ampersands in the URL's for validation purposes.

    :)
     
    duenna, Nov 1, 2005 IP
  8. Toonces51

    Toonces51 !@#$%^&*^%#@#$%

    Messages:
    107
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #8
    I would have done an animated gif, but I didn't want to logo to actually rotate on while they were on the page--I just wanted there to be a different logo as they click thru to different pages of the site.

    Toonces51
     
    Toonces51, Nov 1, 2005 IP