Hello,
I rewrote the image.module in image_block() to get more than one random image. I mentioned, that sometimes two equal images are shown. I think I found a little bug in image_get_random():
else {
$result = db_query_range(db_rewrite_sql("SELECT DISTINCT(n.nid), RAND() AS rand FROM {node} n WHERE n.type = 'image' AND n.status = 1 ORDER BY rand"), 0, $count);
}
should be:
else {
$result = db_query_range(db_rewrite_sql("SELECT DISTINCT(n.nid), RAND() AS rand FROM {node} n WHERE n.type = 'image' AND n.status = 1 ORDER BY rand"), 0, 0, $count);
}
since I changed this, I get random images.
Tobias
Comments
Comment #1
mdowsett commentedcan the script be changed to only get images from one specific image gallery?
Comment #2
drewish commentednot really a proper patch... see http://drupal.org/patch/create for help creating them.
looking at http://api.drupal.org/api/function/db_query_range/6 it seems like the current parameters are correct... but give this a try and see if it works for you.
Comment #3
vitrex commentedHello drewish
sorry, that I am not familar with making proper patches, but I'll try it next time.
Your patch with is working great and gives me random images.
thank you!
Comment #4
sunCommitted the "else" part of that patch only. That said, it should have worked without this patch already, so the entire issue is a bit weird.
Comment #5
sunReverted this patch, as it was already fixed.
See also #217456: image_get_random: when getting single image DISTINCT isn't needed