Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    Junior Member stomponthis's Avatar
    Join Date
    Nov 2007
    Posts
    6
    Member #
    16065
    Hello!
    I have a image in the top of my webpage and I want it to display one of the four images that are available dynamically whenever the page changes, either refresh or when going to another page within the website. The same layout is on every page (so the image is always there) and the images are all the same size.
    Is there an easy way to do this in HTML code? Or do I need a javascript or something?
    Thanks!

  2.  

  3. #2
    Senior Member Steax's Avatar
    Join Date
    Dec 2006
    Location
    Bandung, Indonesia
    Posts
    1,207
    Member #
    14572
    You will need JS, or to be neater you can also use PHP or any other server-side language you have. HTML alone won't do...

    The JS method would be simply by calling images randomly from an array. The cleaner PHP method is quite similar as well. I suggest you use PHP, because it's cleaner. Does your server support this?
    Note on code: If I give code, please note that it is simply sample code to demonstrate an effect. It is not meant to be used as-is; that is the programmer's job. I am not responsible to give you support or be held liable for anything that happens when using my code.

  4. #3
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,731
    Member #
    5580
    Liked
    718 times
    Using PHP would be the best way (my opinion).

    Name the photos like this:

    p1.jpg
    p2.jpg
    p3.jpg
    p4.jpg

    Decide how they should change ....

    1) by page?
    2) by date?
    3) randomly?
    4) in sequence (for the visitor, using cookies)?
    5) in sequence (by page refresh)?

    and realize you can have any number of photos (not just 4).
    and also it's best to put all photos into a directory just for the photos.

    Let us know how you want to determine which photos are shown and how.


  5. #4
    Junior Member stomponthis's Avatar
    Join Date
    Nov 2007
    Posts
    6
    Member #
    16065
    Quote Originally Posted by mlseim
    Using PHP would be the best way (my opinion).

    Name the photos like this:

    p1.jpg
    p2.jpg
    p3.jpg
    p4.jpg

    Decide how they should change ....

    1) by page?
    2) by date?
    3) randomly?
    4) in sequence (for the visitor, using cookies)?
    5) in sequence (by page refresh)?

    and realize you can have any number of photos (not just 4).
    and also it's best to put all photos into a directory just for the photos.

    Let us know how you want to determine which photos are shown and how.
    Thanks for the help
    I have renamed all the images and put theme in seperate directory.
    I don't want anything too flash, just trying to get the image to change randomly whenever the page refreshes.

    I have tried this script, but couldn't get it to work? Should the php work locally? Because I havnt loaded it onto a server yet.
    Code:
    <?php 
      
      $no = (rand()%5); 
        $no++; 
        $randomfilename = "image".$no.".gif"; 
        
        ?>
    Thanks for the help again!

  6. #5
    Senior Member Ferro's Avatar
    Join Date
    Oct 2006
    Location
    UK
    Posts
    386
    Member #
    14204
    Liked
    5 times
    The php will only work locally if you have some kind of server which supports php installed on your computer for testing.
    I find WAMP 5 is a good place to start. It'll get you off the ground with local sql and php testing. Easy to install.

  7. #6
    Junior Member stomponthis's Avatar
    Join Date
    Nov 2007
    Posts
    6
    Member #
    16065
    Quote Originally Posted by Ferro
    The php will only work locally if you have some kind of server which supports php installed on your computer for testing.
    I find WAMP 5 is a good place to start. It'll get you off the ground with local sql and php testing. Easy to install.
    Cool! Thanks for the tip, I am downloading it now :rambo:

  8. #7
    Senior Member Steax's Avatar
    Join Date
    Dec 2006
    Location
    Bandung, Indonesia
    Posts
    1,207
    Member #
    14572
    Isn't it XAMPP? (Or was it XLAA...? Lol ) Well yeah, if you want a simple snippet that'd do, but only for 5 images.

    It'd do this, though:

    PHP Code:
    <?
    $images 
    = Array(
    "image1.jpg""someotherimage.png""whatever.gif"
    );
    echo 
    $images[array_rand($images)];
    ?>
    (which I think should work.)
    Note on code: If I give code, please note that it is simply sample code to demonstrate an effect. It is not meant to be used as-is; that is the programmer's job. I am not responsible to give you support or be held liable for anything that happens when using my code.

  9. #8
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Also you might to get the image dimensions, if you are getting them dynamically (mlseim's method) you might want to use this.

    If you use something like Steax's example you could store the dimensions in an array, it all depends if you see the gallery becoming larger.

  10. #9
    Senior Member Steax's Avatar
    Join Date
    Dec 2006
    Location
    Bandung, Indonesia
    Posts
    1,207
    Member #
    14572
    He said they're all the same size. But yeah, that'd be useful... If the gallery is going to be expanded further. In such case I suggest making it all OOP oriented.

    The thing that scared me when I started PHP was the sheer amount of computing the server seemed to have to do. I mean, I declare 6 classes in my script. Won't the server break down if every single refresh and request needs to process all of those? Scary, if you ask me...
    Note on code: If I give code, please note that it is simply sample code to demonstrate an effect. It is not meant to be used as-is; that is the programmer's job. I am not responsible to give you support or be held liable for anything that happens when using my code.

  11. #10
    Senior Member Ferro's Avatar
    Join Date
    Oct 2006
    Location
    UK
    Posts
    386
    Member #
    14204
    Liked
    5 times
    Quote Originally Posted by bfsog
    Also you might to get the image dimensions, if you are getting them dynamically (mlseim's method) you might want to use this.

    If you use something like Steax's example you could store the dimensions in an array, it all depends if you see the gallery becoming larger.
    Yes the getimagesize is a useful little gizmo.


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:33 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com