OK. Something strange is going on here. I am using the Effervescence theme with my newly created database. The link is
here (you may have to refresh a few times to get a failed image query). I have shifted a few subalbums around in the folder structure, but I have dumped the cache and ran garbage collection. Occasionally, the random function will reference images that don't exist (intermittent) like it's looking for "stale" db references in its SQL queries. Might anyone have any suggestions as to how to correct it? I haven't made many changes to the DB so far (other than the hit counts and ratings), nor entered any custom titles or descriptions yet. Also of note is the fact that the same thing happens on my wordpress blog using Zenshow's random function as well (see
here). See below for the code I am using. Any help would be most appreciated, as I'm stumped. Thanks!
Here is the line I am running, straight from the theme:
`
<?php $randomImage = getRandomImages(); $randomImageURL = getURL($randomImage); print "<a href='".getURL($randomImage)."' title='Random Picture...'>
getCustomImage(1000, 620, 180, 620, 180, 300, 300)."' alt='".$randomImage->getTitle()."' />"; ?>
`
Here are the functions used to query the DB:
`// Get Random Images
function getRandomImages() {
$result = query_single_row('SELECT '.prefix("images").'.filename,'.prefix("images").'.title, '.prefix("albums").'.folder FROM '.prefix("images").' INNER JOIN '.prefix("albums").' ON '.prefix("images").'.albumid = '.prefix("albums").'.id ORDER BY RAND() LIMIT 1');
$image = new Image(new Album(new Gallery(), $result['folder']), $result['filename']);
return $image;
}
function getURL($image) {
if (zp_conf('mod_rewrite'))
{
return WEBPATH . "/" . urlencode($image->getAlbumName()) . "/" . urlencode($image->name);
}
else
{
return WEBPATH . "/index.php?album=" . urlencode($image->getAlbumName()) . "&image=" . urlencode($image->name);
}
}`
Comments
Looking forward to seeing some responses here. :-)
I think I nailed it. There were a lot of stale entries in my DB from when I moved some folders around in the file structure. I just manually deleted them using phpMyAdmin (taking great care to only remove the ones that were bad references) and then ran a garbage collection again. It seemed to do the trick, cause my gallery stats changed from almost 700 images to half that, and the albums went down in count significantly.
So try that. Backup your DB first though.
I need to find some way to keep the database more in-sync with the filesystem... more selective partial garbage collection (both when anomalies are detected and on a rough schedule) would work well I think...