help me please with randomization

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

jacka18l
Forum Newbie
Posts: 6
Joined: Sun Mar 21, 2004 1:12 pm

help me please with randomization

Post by jacka18l »

i need a script to randomize which picture appears.

the script will NOT grab the images form a folder but it will get them from a link.
thanks
JohnDigweed
Forum Newbie
Posts: 18
Joined: Sun Mar 28, 2004 6:24 pm
Location: root/user/hell

Post by JohnDigweed »

Why not research it? There are plenty of tutorials out there.

No one is going to make you a script, for free that is.
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: help me please with randomization

Post by TheBentinel.com »

jacka18l wrote:i need a script to randomize which picture appears.
The stuff here should give you a good start:

http://www.hotscripts.com/PHP/Scripts_a ... index.html
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

har har har.......

there should be a sticky saying when in doubt look at hotscripts.com
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

lol
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

There is.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

What do you mean by it will be "getting them from a link". Are all the images going to be sent as a string? If you DO want to read a directory, its super easy.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

BUT he DOESN'T want to read them from a directory. he DOES want to get them from a link.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

I'm just unsure of what he means by getting them from a link. Will the user click a link which will generate the random image? Will the image names be sent as post variables?

In the script that finds the random image, how does it get the file names to choose from?

In any event, it's probably easiest to put all the filenames in an array, then call array_rand() to get a random element.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

i think that is what he is doing. he ahs the image links in an array maybe, and wants to know how t get a random one. But he may have them all in a text file. Or maybe one link has a million images and he wants to know how o get one. I dont know. He really didn't say, so its kind of hard to help him!
JohnDigweed
Forum Newbie
Posts: 18
Joined: Sun Mar 28, 2004 6:24 pm
Location: root/user/hell

Post by JohnDigweed »

I think I know what he means. He has a bunch of links to images such as

http://www.yourdomain.com/1.gif
http://www.yourdomain.com/2.gif
http://www.yourdomain.com/3.gif
http://www.yourdomain.com/4.gif
http://www.yourdomain.com/5.gif
http://www.yourdomain.com/6.gif

What he wants to is display these images randomly. Like, if $randimage represented a random image, he would want to display :

<img src="$randimage">
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Maybe he/she will come back one day and clarify it all? ;)
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

7 hours and you're already jumping down the guy's throat mark? :P

maybe he's sleeping! lol
jacka18l
Forum Newbie
Posts: 6
Joined: Sun Mar 21, 2004 1:12 pm

Post by jacka18l »

*was sleeping* lol
yeah i mean like
(excuse the crappy code which is not actually a code at all)

"
array of images
http://www.com/image1.jpg
http://www.com/image2.jpg
http://www.com/image3.jpg
http://www.com/image4.jpg
http://www.com/image5.jpg

get random file and display here
"

not code atall really, but what i want it to do.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

so you have an array of links to images??

Code: Select all

$images = array('http://www.com/image1.jpg','http://www.com/image2.jpg','http://www.com/image3.jpg')
Post Reply