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

CommentFileSizeAuthor
#2 image_354523.patch1.4 KBdrewish

Comments

mdowsett’s picture

can the script be changed to only get images from one specific image gallery?

drewish’s picture

StatusFileSize
new1.4 KB

not 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.

vitrex’s picture

Hello 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!

sun’s picture

Status: Needs review » Fixed

Committed 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.

sun’s picture

Status: Fixed » Closed (won't fix)

Reverted this patch, as it was already fixed.

See also #217456: image_get_random: when getting single image DISTINCT isn't needed