Something Strange with Random Images

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...'>imagegetCustomImage(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

  • I haven't had much time lately to look into mine but I too am getting invalid images in my random photo script I am running.. I have no idea if it is the same as yours or not.. I pulled it off the boards here a while ago..

    Looking forward to seeing some responses here. :-)
  • Chili-

    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. ;)
  • And the script you're running is probably the same thing as mine. I've only seen two variations of it, one is the zenshow function that the wordpress plug uses, and 1 is the posted-on-this-board variety. The Effervescence theme uses the latter.
  • trisweb Administrator
    Garbage collect using the [refresh] link in the stats...

    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...
Sign In or Register to comment.