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

?>

 

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.