I followed the instructions at http://drupal.org/node/492552 on adding pagers. However, the pager does not show on the page and a var_dump() of the output of theme_pager() shows NULL. There is enough content to have the pager show (29 rows are returned by query in $sql). Below is the code that generates the content:

  $perpagecount = 15; // How many items to display per page
  
  // The header has to be defined first to get sorting to work correctly!!!
  $header = array(
    array('data' => 'Name', 'field' => 'name', 'sort' => 'asc'),
    array('data' => 'Present', 'field' => 'occurrences', 'sort' => 'asc'),
  );
  
  $sql = 'SELECT `uid`, `name`, count(*) as occurrences FROM {users} INNER JOIN {content_field_present} ON {users.uid} = {content_field_present}.field_present_uid GROUP BY `uid`, `name`';
  $pager_sql = 'SELECT count(DISTINCT `uid`) FROM {users} INNER JOIN {content_field_present} ON {users.uid} = {content_field_present}.field_present_uid';

  // Make it sortable.  I love it when Drupal does stuff for you... <3
  $sql .= tablesort_sql($header);
  $result = pager_query($sql, $perpagecount, NULL, $pager_sql);
  // The key in the $users array is the uid, the value is an array with the
  // username and the number of times that person is present.
  $users = array();
  while($item = db_fetch_array($result)) {
    $users[$item['uid']] = array(
      'name' => $item['name'],
      'presence' => $item['occurrences'],
    );
  }
  
  $data = array();
  foreach($users as $uid => $user) {
    array_push($data, array(
      '<a href="/atrium/user/' . $uid . '">' . $user['name'] . '</a>',
      '<a href="http://officers.ridgehabitat.com/atrium/officers/attendance?field_type_value_many_to_one_op=or&field_type_value_many_to_one=All&field_present_uid_op=and&field_present_uid[]=' . $uid . '">' . $user['presence'] . '</a>',
      ));
  }
  
  $table = theme_table($header, $data);
  $pager = theme_pager();
  echo $table . $pager;

Comments

pbarnett’s picture

Shouldn't that be theme('pager', $count) or something like that?

tdimg’s picture

correct except that in the OPs code its $perpagecount instead of $count.

DragoonBoots’s picture

I tried that originally; when it didn't work I moved to the theme_pager() thinking I had just misread instructions. I tried theme('pager', $perpagecount) again and it still doesn't work.

jaypan’s picture

What are we looking at? It doesn't make sense that you would be echoing the results - they should be being returned somewhere. This may be what is causing your problem.

Contact me to contract me for D7 -> D10/11 migrations.

DragoonBoots’s picture

I was trying to eliminate other module-type stuff as a source of the problem, so I tried it in a page with the PHP input filter. The only difference in the actual module is that instead of echo on the last line there is a return of the same data.

jaypan’s picture

So you are putting that into a page, not in a module?

Contact me to contract me for D7 -> D10/11 migrations.

DragoonBoots’s picture

It's in a module; the version I pasted above was modified to work in a page. The pager does not work correctly in either. The module code is available at http://www.pastie.org/916678.

jaypan’s picture

I don't see anything glaringly wrong with it.

Try changing this:

$result = pager_query($sql, $perpagecount, NULL, $pager_sql);

to this:

$result = pager_query($sql, $perpagecount, 0, $pager_sql);

Contact me to contract me for D7 -> D10/11 migrations.

DragoonBoots’s picture

That worked! Thanks for your help.

jaypan’s picture

Nice! Glad it helped - it was a shot in the dark.

Contact me to contract me for D7 -> D10/11 migrations.