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 Link to comment https://forums.phpfreaks.com/topic/134300-solved-scrolling-images-on-webpage/ Share on other sites More sharing options...
dezkit Posted November 26, 2008 Share Posted November 26, 2008 Please elaborate. Link to comment https://forums.phpfreaks.com/topic/134300-solved-scrolling-images-on-webpage/#findComment-699197 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. Link to comment https://forums.phpfreaks.com/topic/134300-solved-scrolling-images-on-webpage/#findComment-699217 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> Link to comment https://forums.phpfreaks.com/topic/134300-solved-scrolling-images-on-webpage/#findComment-699310 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>'; Link to comment https://forums.phpfreaks.com/topic/134300-solved-scrolling-images-on-webpage/#findComment-699322 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 Link to comment https://forums.phpfreaks.com/topic/134300-solved-scrolling-images-on-webpage/#findComment-700028 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 Link to comment https://forums.phpfreaks.com/topic/134300-solved-scrolling-images-on-webpage/#findComment-700036 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>'; Link to comment https://forums.phpfreaks.com/topic/134300-solved-scrolling-images-on-webpage/#findComment-700046 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 Link to comment https://forums.phpfreaks.com/topic/134300-solved-scrolling-images-on-webpage/#findComment-700050 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. Link to comment https://forums.phpfreaks.com/topic/134300-solved-scrolling-images-on-webpage/#findComment-700053 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>'; ?> Link to comment https://forums.phpfreaks.com/topic/134300-solved-scrolling-images-on-webpage/#findComment-700057 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 Link to comment https://forums.phpfreaks.com/topic/134300-solved-scrolling-images-on-webpage/#findComment-700074 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>'; Link to comment https://forums.phpfreaks.com/topic/134300-solved-scrolling-images-on-webpage/#findComment-700131 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. Link to comment https://forums.phpfreaks.com/topic/134300-solved-scrolling-images-on-webpage/#findComment-700312 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! Link to comment https://forums.phpfreaks.com/topic/134300-solved-scrolling-images-on-webpage/#findComment-700796 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.