You are here: Re: [PHP] Random Images with no duplicates? « PHP « IT news, forums, messages
Re: [PHP] Random Images with no duplicates?

Posted by "Silvio Porcellana [tradeOver]" on 12/18/05 11:59

Jared Williams wrote:
> Hi,
> Just unset the ones you've picked
>
> <?php
> #random images example
> #this is your file
> $file = "images.txt";
> #open the file
> $openFile = file($file);
> #generate a random number
> srand((double)microtime()*1000000);
> #get one of the entries in the file
> for ($i = 0; $i < 10; ++$i)
> {
> $r = array_rand($openFile);
> $random_image = $openFile[$r];
> echo "<img src='$random_image' height='170' width='100'></img>";
> unset($openFile[$r]);
> }
> ?>
>
> Jared
>

Sorry if I jump in late in this thread, but wouldn't this work?

<code>
$file = "images.txt";
$openFile = file($file);
$num_images = 10;
# don't need this is PHP > 4.2.0
srand((float) microtime() * 10000000);
$random_keys = array_rand($openFile, $num_images);
foreach ($random_keys as $random_key) {
echo "<img src='$random_image' height='170' width='100'></img>";
}
</code>

array_rand: http://php.net/array_rand

Maybe I'm missing something... Anyway, cheers everybody!

Silvio

--
tradeOver | http://www.tradeover.net
....ready to become the King of the World?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация