IronWarrior Posted July 31, 2008 Share Posted July 31, 2008 Hello All, Just a quick question I am using this code: $directoryName = "images/".$trimmedRandomVehicleName; $handle=opendir("$directoryName"); while (($file = readdir($handle))!==false) { if ($file != "." && $file !="..") { ?> <img src=<? echo "images/".$trimmedRandomVehicleName."/".$file?>> <? } } closedir($handle); ?> This gets all of the images from a directory and displays them, But i need to add a second while loop so it only displays one of those images, and if possible just a random image from that directory... Can anyone help me with this? Link to comment https://forums.phpfreaks.com/topic/117541-solved-nested-loops/ Share on other sites More sharing options...
rhodesa Posted July 31, 2008 Share Posted July 31, 2008 like this? <?php $directoryName = "images/".$trimmedRandomVehicleName; $handle=opendir("$directoryName"); $files = array(); while (($file = readdir($handle))!==false) { if ($file != "." && $file !="..") { $files[] = $file; } } closedir($handle); $file = $files[array_rand($files); ?> <img src="<? echo $directoryName."/".$file?>"> Link to comment https://forums.phpfreaks.com/topic/117541-solved-nested-loops/#findComment-604563 Share on other sites More sharing options...
IronWarrior Posted July 31, 2008 Author Share Posted July 31, 2008 Very good idea, Thanks for the assistance topic solved. Link to comment https://forums.phpfreaks.com/topic/117541-solved-nested-loops/#findComment-604572 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.