This should be simple

Discussion in 'HTML & Website Design' started by DMK, Oct 27, 2007.

  1. #1
    I plan to create a webpage like this, which visited/refreshed every time shows a different image. I can understand that the images have to be loaded on the server but how to put the script which changes the images randomly on each new refresh.
     
    DMK, Oct 27, 2007 IP
  2. scriptman

    scriptman Peon

    Messages:
    175
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That is easy. You can just set up a directory to store the rotated images, then set up a PHP script (or any other language) to read in each filename into an array, generate a random number to use as the array item number, then output the source located at that item number.

    If you're in a rush, here's some example code: http://www.alistapart.com/d/randomizer/rotate.txt (You can read more about it here).

    Good luck!
     
    scriptman, Oct 27, 2007 IP
  3. grikis

    grikis Banned

    Messages:
    333
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    php.net/rand php.net/array
     
    grikis, Oct 27, 2007 IP
  4. twistedspikes

    twistedspikes Notable Member

    Messages:
    5,694
    Likes Received:
    293
    Best Answers:
    0
    Trophy Points:
    280
    #4
    you can create a php script to randomly display images (like I have on my site to show the 'features layout', the top one in my sig)

    if you want the script pm me and i'll send you it.
     
    twistedspikes, Oct 27, 2007 IP
  5. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Reading a directory is one option but for a faster response time, esp if you start having a lot of images then it would be better to store a directory of images either in an XML file or a database.

    By doing this you also have the option of weighting images so that some appear more frequently than others if this becomes necessary in the future.
     
    AstarothSolutions, Oct 27, 2007 IP