Looking for Random Image Solution

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

Post Reply
Patow
Forum Newbie
Posts: 1
Joined: Tue Oct 10, 2006 8:38 pm

Looking for Random Image Solution

Post by Patow »

I'm looking for a Random image solution (PHP/HTML) where I have a page with a table (say 5 x 5), and I want a random image displayed in each table cell. There are a couple of caviats:

1) I don't want duplicate images in the table
2) I want the photos to be thumbnails, and have them link to the source file
3) I'm hoping to have a scalable solution so I can have tables bigger than 5 x 5 without duplicate files, and without a ton of manual labour to add new pictures to the mix.

Can anyone point me to an existing documented solution?

Thanks,

Dave
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post by ambivalent »

Off the top of my head, you'd have your thumbs in an array and use shuffle or maybe array_rand to pick out the thumbs to display.

Search this forum for "random image", this has been discussed before and you should turn up a few ideas.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

pseudo code:
  • get image file names into an array
  • randomize the array
  • randomly pick a value from the array
  • check if the filename picked from the array is not in the second array
  • put that filename into a second array that holds the filenames already picked
  • display the image
  • wash
  • rinse
  • repeat
Post Reply