PHP Displaying Random Product with URL?

http://militarypewter.com/wordpress/?page_id=148

My current script displays 3 random images from a folder, but not bringing url with it. I just did this 3 different times. So now if you click i have it sending you back to products which isnt good

<?php
function getRandomFromArray($ar) {
mt_srand( (double)microtime() * 1000000 );
$num = array_rand($ar);
return $ar[$num];
}

function getImagesFromDir($path) {
$images = array();
if ( $img_dir = @opendir($path) ) {
while ( false !== ($img_file = readdir($img_dir)) ) {
// checks for gif, jpg, png
if ( preg_match("/(\.gif|\.jpg|\.png)$/", $img_file) ) {
$images[] = $img_file;
}
}
closedir($img_dir);
}
return $images;
}

$root = '';
// If images not in sub directory of current directory specify root
//$root = $_SERVER['DOCUMENT_ROOT'];

$path = '../images/products/thumbs/';

// Obtain list of images from directory
$imgList = getImagesFromDir($root . $path);

$img = getRandomFromArray($imgList);

?>

then echo

<a href="?page_id=22"><img width="100px" height="100px" src="<?php echo $path . $img ?>" alt="" /></a>

Can someone please help?
 
Back
Top