How do I randomly rotate an image on a webpage after each page refresh?

Discussion in 'Web Design and Development' started by macaddict23, May 22, 2008.

  1. macaddict23 macrumors 6502

    macaddict23

    Joined:
    Jun 20, 2006
    Location:
    MacVille, USA
    #1
    Also, instead of an image, can I randomly rotate an entire page? Thanks!
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Yup, sure, just add the following near the top of your page,

    Code:
    To see this page sideways close your eyes tilt your head 90 degrees to the right or left, then open your eyes.
    HTML doesn't have these capabilities. You could potentially do it with a flash page, but don't really see why anyone would want to do this as it would be a horrible user experience. If you wanted to rotate an image you would need two different image files showing the different rotations, and then you'd use JavaScript to switch out the files.
     
  3. RBMaraman macrumors 65816

    RBMaraman

    Joined:
    Jul 25, 2002
    Location:
    Prospect, KY
    #3
    Umm... I don't think that's what the poster means.

    I take it that he has a couple of different images, and when someone clicks refresh, he wants an image to randomly appear.
     
  4. jambla macrumors newbie

    Joined:
    Jun 6, 2008
    #4

    Hello Macaddict23,

    This is a simple way to rotate an image on refresh or page load.

    PHP:
    <img src="<? echo rand(110); ?>.gif" height="THE HEIGHT" width="THE WIDTH" border="0"/>
    This method uses PHP so you will need PHP on your server, however most linux servers have PHP installed by default.

    The explanation of the code:

    <? - This open a PHP session.
    echo - This is a way to output something in PHP
    rand(1, 10) - This is a random function in PHP. In this case I assumed you had 10 images that you wanted to possibly output. If you had 4 images your random function would look like this rand(1, 4).
    ?> - This closes the PHP sesstion.
    .gif - You image format. This can be any file extension.

    If you have a question on need clarifications please let me know.

    Jambla
     

Share This Page