My goal is to allow refreshing a gallery sample in a section of our site's home page. I can only get it to refresh once, however. Any other solution creates endless nested calls. Here's what I've got on the public page:
<?php include_once("./pix/cpmfetch/cpmfetch.php");
$objCpm = "";
$objCpm = new cpm("./pix/cpmfetch/cpmfetch_config.php"); ?>
<div id=galsamp>
<?php include('./gallerysample.php'); ?>
<script language="JavaScript">
function refreshgalsamp() {
document.getElementById('galsamp').innerHTML='<?php include("./gallerysample.php") ?>';
}
</script>
<a href="javascript:refreshgalsamp();">Refresh</a></font>
</div>
where gallerysample.php is simply:
<?php
$objCpm->cpm_viewRandomMedia(5,1);
?>
The "Refresh" link is inside the <div> because it doesn't work a second time.
continued ...
I've been trying another approach with no more success, namely, creating an array of the entire gallery in Javascript. But again, only one refresh is possible. In fact, the refresh doesn't finish processing, so it probably embarkis on some endless looping, although I don't see what. Here is what I've got:
<head>
<script>
var Pic = new Array()
<?php
include "./pix/cpmfetch/cpmfetch.php";
$objCpm = new cpm("./pix/cpmfetch/cpmfetch_config.php");
$objCpm->cpm_setReturnType("resultset");
$data = $objCpm->cpm_viewRandomMedia(50, 50, "");
$a = 0;
foreach ($data as $row) {
$imagethumb = $objCpm->getImageToUse($row['pFilepath'], $row['pFilename'], "thumb_");
$imagepage = "./pix/displayimage.php?pos=-" . $row['pPid'];
print "Pic[" . $a . "]='<a href=" . $imagepage . "><img src=./pix/" . $imagethumb . "></a>'\n";
$a = $a + 1;
}
?>
function pix() {
document.write("<table>");
i=0;
while(i<5) {
document.write("<tr><td>");
document.write(Pic[Math.floor(Math.random()*Pic.length)]);
document.write("</td></tr>");
i++;
}
document.write("</table>");
}
</script>
</head>
<body>
<div id=galsamp>
<script>pix();</script>
</div>
<a href='javascript:document.getElementById("galsamp").innerHTML=pix();'>Refresh</a>
</body>
Actually, it appears that the refresh link is ignoring the innerHTML command and just running pix(), because the refresh link disappears. Plus, the refresh continues to run after displaying new pictures.
Use AJAX: http://forum.coppermine-gallery.net/index.php?topic=51895