I've modified a snippet of code from this very site that builds an image array from a folder and then rotates through the images in sequence. The modification i made values a random <img id=x> to a random entry in the image array of 19 items.
partA: the html.
partB:getimages.php.
I've never posted here before so i hope i posted this right w the tags.

I know partB works.
PartA shows no image change when run. I am not sure how to step through this in firebug but there appears to be no js errors.
Any thoughts would be greatly appreciated.
Kindest regards,
David

Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<script src="getimages.php"></script>
<script type="text/javascript">
function rotateimages(){
<?php 
$thetd =rand(1,8); 
$theimg=rand(1,19);
echo 'document.getElementById("p'.$thetd.'").setAttribute("src", "images/smimages/"+galleryarray['.$theimg.']);'
?> 
}

window.onload=function(){
setInterval("rotateimages()", 2500)
}
</script>
<table>
<tr>
<td><img id="p1" src="images/smimages/Copa3sm.jpg" /></td>
<td><img id="p2" src="images/smimages/TommySm.jpg" /></td>
<td><img id="p3" src="images/smimages/ViSm.jpg" /></td>
<td><img id="p4" src="images/smimages/TrioSm.jpg" /></td>
<td><img id="p5" src="images/smimages/rom2sm.jpg" /></td>
<td><img id="p6" src="images/smimages/sp2sm.jpg" /></td>
<td><img id="p7" src="images/smimages/pr3sm.jpg" /></td>
<td><img id="p8" src="images/smimages/PelSm.jpg" /></td>
</tr>
</table>
</body>
</html>

the php code:
<?
//PHP SCRIPT: getimages.php
Header("content-type: application/x-javascript");

//This function gets the file names of all images in the current directory
//and ouputs them as a JavaScript array
function returnimages($dirname="images/smimages/") {
$pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)"; //valid image extensions
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){ //if this file is a valid image
//Output it as a JavaScript array element
echo 'galleryarray['.$curimage.']="'.$file .'";';
$curimage++;
}
}

closedir($handle);
}
return($files);
}

echo 'var galleryarray=new Array();'; //Define array in JavaScript
returnimages() //Output the array elements containing the image file names
?>
I wanted to thank the original individual for the core piece of this code.
It works great. An they are a good php developer.
cheers