Jump to content

Random Image but how to structure the array to link to Flickr?


Mouse

Recommended Posts

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\" />";

?>

 

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>";

?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.