Mouse Posted December 29, 2007 Share Posted December 29, 2007 For a while now I have been using the following “Random Image” code to display an image into the index page of my site http://afterthemouse.com but now I need to extend it’s scope a little. I need to add a link back to the photographers Flickr account to each photo. How do I structure the array? The thumbnails will be stored locally and serve as a link to the full size Flickr image Many thanks <?php /* images named 1.jpg, 2.jpg etc. */ // total number of images in the folder $total = "11"; $file_type = ".jpg"; // location of the folder containing the images $image_folder = "images/random"; $start = "1"; $random = mt_rand($start, $total); $image_name = $random . $file_type; echo "<img src=\"$image_folder/$image_name\" alt=\"$image_name\" />"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/83575-random-image-but-how-to-structure-the-array-to-link-to-flickr/ Share on other sites More sharing options...
Mouse Posted December 29, 2007 Author Share Posted December 29, 2007 Thinking about this, would it be the time to use CASE? if so, how so?... sorry, still a noobie here. i got sidetracked from PHP by having children... Quote Link to comment https://forums.phpfreaks.com/topic/83575-random-image-but-how-to-structure-the-array-to-link-to-flickr/#findComment-425183 Share on other sites More sharing options...
Mouse Posted December 29, 2007 Author Share Posted December 29, 2007 maybe somthing like...? <?php /* images named 1.jpg, 2.jpg etc. */ // total number of images in the folder $total = "11"; $file_type = ".jpg"; // location of the folder containing the images $image_folder = "images/random"; $start = "1"; $random = mt_rand($start, $total); switch ($url) { case 1: echo "http://flickr.com/photos/account_123"; break; case 2: echo "http://flickr.com/photos/account_246"; break; default: echo "http://flickr.com/"; } $image_name = $random . $file_type; echo "<a href=\"$url\"><img src=\"$image_folder/$image_name\" alt=\"$image_name\" /></a>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/83575-random-image-but-how-to-structure-the-array-to-link-to-flickr/#findComment-425189 Share on other sites More sharing options...
teng84 Posted December 29, 2007 Share Posted December 29, 2007 if you get the data ibto your DB just use order by rand() and get the id of each record if that5 is an array only add a array index that will determine that id of that image or photographer so when you random your image the index is always ready to be used Quote Link to comment https://forums.phpfreaks.com/topic/83575-random-image-but-how-to-structure-the-array-to-link-to-flickr/#findComment-425232 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.