un testested as no database to check with and not got time to create one but should be nearly ther
no extra java needed its in the link
echo "\n\nThere are $totalrows photo's from $img_title";
echo "<table border=1 cellpadding=1 width=100% cellspacing=0 bordercolor='#000000'>\n".
"<tr><td bgcolor='#333333'><div align ='right'>$img_title</div></td></tr><tr><td bgcolor='#333333' colspan='2'>$img_descrip</td></tr><tr>\n";
for ($count = 0; $count < $limit ; $count++) {
// Extract post details from database
$myrow = mysql_fetch_array($result);
$img_id = $myrow ['img_id'];
$img_ref = $myrow ['img_ref'];
$img_ref_2 = $myrow ['img_ref_2'];
$ref = substr($myrow ['img_ref_2'], 0, -4);
printf("<td><div align='center'><a href=\"viewImage.php?img_id=$img_id\" onClick=\"var myh=window.open(this.href,'Popup_Window',
'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,width=200,height=200');return(false);\">
<img src=../images/$img_ref/$img_ref_2 width='200' height='200' alt='Click to enlarge'></a></td>\n");//.
$hold[]="<td bgcolor='#000099'><div align='center'>Image Refrence: $ref</div></td>";
if(isset($hold[1]))
{
echo "</tr><tr>".$hold[0].$hold[1]."</tr><tr>";
unset($hold);
}
}
if(isset($hold))
echo"</tr><tr>".$hold[0];
echo "</tr></table>\n";