I had a question about some nonsense that I've writen, hopefully one of you generous people can help me out.
What I'm trying to accomplish here is to generate links to random images, but not to have repeating images. Meaning the same image doesn't appear twice on the page. I have a directory full of images with the same name except for there being incremental numbers at the end of the filename. I'm trying to plug randomly generated numbers ( $thumb ) into the <img> link, using "if" to check for duplicates. It doesn't work quite the way I want it to. lol
Any pointers would be very helpful!
Code: Select all
<?php
$thumb1 = rand(0, 4);
$thumb2 = rand(0, 4);
$thumb3 = rand(0, 4);
$thumb4 = rand(0, 4);
$thumb5 = rand(0, 4);
if (($thumb1 == $thumb2) || ($thumb1 == $thumb3) || ($thumb1 == $thumb4) || ($thumb1 == $thumb5))
{
$thumb1 = rand(1, 4);
}
echo '<img src="images/thumbs/thumb'.$thumb1.'.jpg" border="0"> '."\n";
if (($thumb2 == $thumb1) || ($thumb2 == $thumb3) || ($thumb2 == $thumb4) || ($thumb2 == $thumb5))
{
$thumb2 = rand(1, 4);
}
echo '<img src="images/thumbs/thumb'.$thumb2.'.jpg" border="0"> '."\n";
if (($thumb3 == $thumb1) || ($thumb3 == $thumb2) || ($thumb3 == $thumb4) || ($thumb3 == $thumb5))
{
$thumb3 = rand(1, 4);
}
echo '<img src="images/thumbs/thumb'.$thumb3.'.jpg" border="0"> '."\n";
if (($thumb4 == $thumb1) || ($thumb4 == $thumb3) || ($thumb4 == $thumb3) || ($thumb4 == $thumb5))
{
$thumb4 = rand(1, 4);
}
echo '<img src="images/thumbs/thumb'.$thumb4.'.jpg" border="0"> '."\n";
if (($thumb5 == $thumb1) || ($thumb5 == $thumb3) || ($thumb5 == $thumb3) || ($thumb5 == $thumb1))
{
$thumb5 = rand(1, 4);
}
echo '<img src="images/thumbs/thumb'.$thumb5.'.jpg" border="0"> '."\n";
?>