• Welcome to The Cave of Dragonflies forums, where the smallest bugs live alongside the strongest dragons.

    Guests are not able to post messages or even read certain areas of the forums. Now, that's boring, don't you think? Registration, on the other hand, is simple, completely free of charge, and does not require you to give out any personal information at all. As soon as you register, you can take part in some of the happy fun things at the forums such as posting messages, voting in polls, sending private messages to people and being told that this is where we drink tea and eat cod.

    Of course I'm not forcing you to do anything if you don't want to, but seriously, what have you got to lose? Five seconds of your life?

An image randomizer that doesn't mess up your whole page?

Ivy Newton

kg*m/s^2
Pronoun
she
Ya see, I'm trying to put an image randomizer on this webpage I'm making for a school project. But the ones I found online failed. The first one (in PHP) literally killed my webbie (though I think it's partially my own stupidity that did it) and I had to scramble and rename multiple files to get it fixed, and the second one (in Javascript) messed up the layout quite a bit.

Anyone have a reliable image randomizer script?
 
I see "dreamweaver" in the tags and have to say that that is probably the problem. :/
 
I see "dreamweaver" in the tags and have to say that that is probably the problem. :/

As in Dreamweaver doesn't support image randomizers? Or as in the layout is usually messed up in Dreamweaver's preview screen?

Well, it doesn't matter cause I finally found one. Somewhere.
 
What language do you want it to be in?

postninjaed: Dreamweaver is horrible, I suggest you get a text editor. They can work wonders.
And it is impossible to not support an image randomizer.
 
What language do you want it to be in?

postninjaed: Dreamweaver is horrible, I suggest you get a text editor. They can work wonders.
And it is impossible to not support an image randomizer.

Actually I use Dreamweaver as I would a text editor, but the point of the class is partially that I learn Dreamweaver, so I'm kinda stuck with it.

Are Javascript or PHP ones better?
I managed to find a working Javascript one, but if PHP is better and you have the code (and step by step instructions, cause i managed to kill my webbie with the last PHP one I tried), then I'll consider it.
 
Dreamweaver preview wouldn't work with PHP because you don't have PHP installed, most likely. Agreeing with the above: if you're serious about this, get a good text editor. Anything more only drags you down.

eta: as for which is better, well, depends. Javascript is client side, which means you don't have to worry about support, but people do browse with it switched off; PHP (is terrible) is server-side, so you'd need hosting that supports it, although in the long run it is probably more flexible.
 
This is really a simple randomizer script; I could write up one myself. Of course, this assumes you know basic PHP.

So, make a list of the directions to the image files. Put them into an array by doing the following:

Code:
$imagelist = array("imageone.ext", "imagetwo.ext", "imagethree.ext", "etc.ext");

Obviously, replace the psuedonames with your own. Then, for the random part:

Code:
$result = $imglist[rand(0,sizeof($imglist))];

Of course, you can name the variables whatever you'd like, but this is for the sake of example. Now, putting it in the actual web page:

Code:
<img src="<?php echo $result; ?>" />

This should make an image tag with the random image's directory and/or filename with it, correctly displaying the image.
Also, make sure the first two code blocks are actually within "<?php" and "?>" tags, or else it would be interpreted as the HTML of the page.

edit: if you need a JS one, just ask.
 
Thankies for all the info~
I should probably find out about hosting and if PHP is installed and stuff...
That's probably pretty important. :grin:


Dreamweaver preview wouldn't work with PHP because you don't have PHP installed, most likely. Agreeing with the above: if you're serious about this, get a good text editor. Anything more only drags you down.
With the PHP one I tried it wasn't that the layout didn't work, it was that I couldn't preview it in a browser at all. I think I majorly messed something up cause I'm still pretty unfamiliar with Dreamweaver and it was making me do something with something or other that I didn't understand. Heh.

Edit: And if I ever make my own site (read: not a school project) I probably will just use a text editor. I actually rather like doing my coding with Notepad, even.
 
Last edited:
Back
Top Bottom