How do I do an image rotation?

Discussion in 'Graphics & Multimedia' started by irideflatland, Jul 20, 2006.

  1. #1
    For instance - http://www.fpsgaming.us/ascension_superjump.html
    I want the pic next to AdSense to be swapped out with different pics randomly. I did a search on here and found a php script, but I couldn't get it to work.

    PLEASE I need some help :)
     
    irideflatland, Jul 20, 2006 IP
  2. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #2
    Assuming you can use PHP...

    
    $my_urls = array(
        'url1',
        'url2',
        'url3',
    );
    
    $url2use = rand(0,count($my_urls)-1);
    
    PHP:
    Then in the HTML...

    
    <img src="<?php echo $my_urls[$url2use]; ?>" alt="" border="0" />
    
    HTML:
    I use that for some other stuff and it should do the job for you.
     
    noppid, Jul 20, 2006 IP
    irideflatland likes this.
  3. candidindia

    candidindia Peon

    Messages:
    86
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks noppid,

    That's really elaborate and helpful.
     
    candidindia, Jul 21, 2006 IP
  4. irideflatland

    irideflatland Banned

    Messages:
    515
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Alright, I'm a n00b, so I need some more detailed help ;)

    I want to test it out on the link up top, with the Halo 3 picture by AdSense. I set up a folder for rotation images (root/images/rotation) and it has 2 images in there.

    I know my server allows PHP, but I don't exactly know how to use it, so can you help me a little more please?
    Thanks :)
     
    irideflatland, Jul 21, 2006 IP
  5. irideflatland

    irideflatland Banned

    Messages:
    515
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This is my test page I'm trying it on, but I can't get it to work - http://www.fpsgaming.us/test2.html
    EDIT: I just tried naming it to a .php file, and it worked. But I don't want to rename all my files, so is there a way I can call the function or whatever?

    EDIT: I hate PHP and I just am going to use JavaScript :)
     
    irideflatland, Jul 21, 2006 IP
  6. stupidfly

    stupidfly Peon

    Messages:
    129
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I love PHP. I guess if I had to rename hundreds of files, I would hate it too.
     
    stupidfly, Jul 21, 2006 IP
  7. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #7
    root/images/rotation is probably above public_html or htdocs? If so, even if you code the php correct, you won't be able to see images. The webserver can't get to them. EDIT: your images display fine, do the step below.

    Secondly, you need a little addition to the .htaccess file on that site to tell it to parse PHP in your html file.
    Add this line to your .htaccess file...

    
    AddType application/x-httpd-php .php .html
    
    Code (markup):

    Your example page looks correct except to address those two issues. Don't give up, you are 99% there. :)
     
    noppid, Jul 21, 2006 IP
  8. irideflatland

    irideflatland Banned

    Messages:
    515
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I don't have a pubmlic_html or htdocs I don't think, and the webserver must be able to get to the pics, because it's working with JavaScript.

    Also, I added that file and it did nothing, then I added a different .htaccess and it made you download my pages instead of viewing them, so I gave up.
     
    irideflatland, Jul 21, 2006 IP
  9. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #9
    Yes, I see them. I edited my post before you read it I guess.

    What type server are you on, windows or *nix? Do you know if the web server is apache? This is not an expert addition. We should be able to sort it out for you.

    JS will be fine if you can do that too I'd guess.
     
    noppid, Jul 21, 2006 IP
  10. irideflatland

    irideflatland Banned

    Messages:
    515
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #10
    irideflatland, Jul 21, 2006 IP
  11. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #11
    Nice job. That looks nice.

    Just goes to show, there's more then one way to skin a cat. ;)

    I don't know godaddy hosting to help here. I know I have not read good things about it. Maybe someone that does use it can let us know how you can get them to parse php in html.
     
    noppid, Jul 21, 2006 IP
  12. irideflatland

    irideflatland Banned

    Messages:
    515
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Well I saw the Godaddy commercials on TV and the ladies had big boobs so I bought from them ;) Just kidding, but I did buy because of their commercial. I didn't know anything about domains/hosting, so I went with the only one I saw advertised.
     
    irideflatland, Jul 21, 2006 IP
  13. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #13
    I have never used it, so my opinion is not a good one to follow. I can't imagine that you can't do what you need done though.

    I was hoping someone with GD hosting would jump in and give you a tip. That may still happen. Don't let my comment cause to to make a decision without more information.
     
    noppid, Jul 21, 2006 IP