have a view, which displays as a list in a page, with 20 nodes per page, across 3 pages. I am displaying the results in random ascending order.

Once the first page is displayed and I decide to go to the next page by selecting either page 2, next or last at the bottom I run into the issue that I get the results regenerated. So instead of getting page 2 of my original search, it seems to give me a new set of results on page 2. However I still have the ability to go back to page 1 or 3, so it realises it's still on page 2.

Is it possible to have my original search displayed throughout the 3 pages, so that nodes aren't displayed on all 3 pages potentially?

Comments

merlinofchaos’s picture

Status: Active » Closed (won't fix)

Alas, it is not possible. Combining pagination and random order simply doesn't work. Sorry about that, but there's nothing that can be done there.

swentel’s picture

Version: 5.x-1.5 » 6.x-2.x-dev
Status: Closed (won't fix) » Active

Hi Earl,

This is possible if you add an argument in the mysql RAND() function, it is used as the seed value, which produces a repeatable sequence of column values. see http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#funct...

So add a seed like the snippet underneath (views 2 implementation) and it works fine.

I'm currently working on a new handler, should I post a patch for views 2 core for a new handler called 'random with seed' or extend the existing one or even create a new module ? A lot of settings appear on the random field like:

- Use the same seed for every user
- Use a random seem per user
- Reset the seed - every day - every hour - never
- Define your own seed: ____

There might even be an option to not cache the page if we're serving pages to anonymous users, which would use a hook_exit I guess and currently doesn't exists in views.module. This probably justifies a new module I guess as I can imagine you don't want this hook in views 2 core.

class views_handler_sort_random extends views_handler_sort {
  function query() {
    global $db_type;
    // Define a seed, currently always the same but this might have a lot of settings ..
    $seed = 3;
    switch ($db_type) {
      case 'mysql':
      case 'mysqli':
        $formula = 'RAND('. $seed .')';
        break;
      case 'pgsql':
        $formula = 'RANDOM('. $seed .')';
        break;
    }
    $this->query->add_orderby(NULL, $formula, $this->options['order'], '_' . $this->field);
  }

  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $form['order']['#access'] = FALSE;
  }
}
swentel’s picture

Status: Active » Closed (fixed)

Will become a seperate module, look out for views_random_seed in like an hour or so.

boreg’s picture

Just want to include a link to that module: http://drupal.org/project/views_random_seed