Looktrne Posted November 26, 2008 Share Posted November 26, 2008 Ok I have a webpage and I have a folder full of thumnail images so how could I get the images scrolled in order or randomly to make the home page constantly scroll the images from that image folder? what is the best way to do this? hope you can understand my question Paul Quote Link to comment Share on other sites More sharing options...
dezkit Posted November 26, 2008 Share Posted November 26, 2008 Please elaborate. Quote Link to comment Share on other sites More sharing options...
br3nn4n Posted November 26, 2008 Share Posted November 26, 2008 Load the images into a javascript array, and randomly order them. Then give each one a <img src tag. Php may be useful in getting the filename of each file in the folder. Quote Link to comment Share on other sites More sharing options...
chmpdog Posted November 26, 2008 Share Posted November 26, 2008 javascript would be easiest, but you could also: <scroll> // get the images from database <? for (i=0, i < $num_rows, $i++) { // do the image thing } ?> </scroll> Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted November 26, 2008 Share Posted November 26, 2008 Is this what you want? echo '<marquee>'; $files = 'images/thumbs/*.jpg'; foreach(glob($files) as $file){ echo '<img src="'.$file.'">'; } echo '</marquee>'; Quote Link to comment Share on other sites More sharing options...
Looktrne Posted November 27, 2008 Author Share Posted November 27, 2008 chmpdog hey yea that is cool... I will play around with that thanx Paul Quote Link to comment Share on other sites More sharing options...
Looktrne Posted November 27, 2008 Author Share Posted November 27, 2008 ok now I have another problem I tested this on a site with about 100 photos in the folder. say I have 17,000 photos in the folder how can I have it randomly grab 200 of the photos? thanks for any help with this Paul Quote Link to comment Share on other sites More sharing options...
trq Posted November 27, 2008 Share Posted November 27, 2008 echo '<marquee>'; $files = glob('images/thumbs/*.jpg'); for ($i=0;$i<=100;$i++) { echo '<img src="' . $files[$i] . '">'; } echo '</marquee>'; Quote Link to comment Share on other sites More sharing options...
Looktrne Posted November 27, 2008 Author Share Posted November 27, 2008 ok that looks like it would grab the first 100? or will that grab them randomly? thanks Paul Quote Link to comment Share on other sites More sharing options...
trq Posted November 27, 2008 Share Posted November 27, 2008 Sorry, <?php function getrandom($amount, $min, $max, $arr=array()) { $rand = rand($min, $max); while (count($arr) < $amount-1) { if (!in_array($rand, $arr) { $arr[] = $rand; } else { getrandom($amount, $min, $max, $arr); } } return $arr; } echo '<marquee>'; $files = glob('images/thumbs/*.jpg'); $random = getrandom(200, 0, count($files)); foreach ($random as $rand) { echo '<img src="' . $files[$rand] . '">'; } echo '</marquee>'; ?> Carefull, its not tested. Quote Link to comment Share on other sites More sharing options...
trq Posted November 27, 2008 Share Posted November 27, 2008 Carefull, its not tested. Now it is. <?php function getrandom($amount, $min, $max, &$arr=array()) { $rand = rand($min, $max); while (count($arr) < $amount-1) { if (!in_array($rand, $arr)) { $arr[] = $rand; } else { getrandom($amount, $min, $max, $arr); } } return $arr; } echo '</marquee>'; $files = glob('images/thumbs/*.jpg'); $random = getrandom(200, 0, count($files)-1); foreach ($random as $rand) { echo '<img src="' . $files[$rand] . '">'; } echo '</marquee>'; ?> Quote Link to comment Share on other sites More sharing options...
Looktrne Posted November 27, 2008 Author Share Posted November 27, 2008 thanks just had to change the </marquee> to <marquee> Paul Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted November 27, 2008 Share Posted November 27, 2008 This is less code: $img_array = glob("images/thumbs/*.jpg"); //Pick a random image from the array for($i=0;$i<200;i++){ $img = array_rand($img_array); //Display the image on the page $display .='<img alt="'.$img_array[$img].'" src="'.$img_array[$img].'" />'; } echo '<marquee>'.$display.'</marquee>'; Quote Link to comment Share on other sites More sharing options...
trq Posted November 27, 2008 Share Posted November 27, 2008 This is less code: $img_array = glob("images/thumbs/*.jpg"); //Pick a random image from the array for($i=0;$i<200;i++){ $img = array_rand($img_array); //Display the image on the page $display .='<img alt="'.$img_array[$img].'" src="'.$img_array[$img].'" />'; } echo '<marquee>'.$display.'</marquee>'; Your code could easily repeat an image, mine won't. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted November 28, 2008 Share Posted November 28, 2008 This is less code: $img_array = glob("images/thumbs/*.jpg"); //Pick a random image from the array for($i=0;$i<200;i++){ $img = array_rand($img_array); //Display the image on the page $display .='<img alt="'.$img_array[$img].'" src="'.$img_array[$img].'" />'; } echo '<marquee>'.$display.'</marquee>'; Your code could easily repeat an image, mine won't. Good point! I could make it so it won't, but this topic is solved! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.