Question

I have a table with data from the database, I would like it to have a Pager, I have all the code from an example (of buildamodule.com) among other sites, and my table get's rendered, but it doesn't generate a pager, although I have more rows then the limit:

enter image description here

the function:

function get_loyaltycodes(){
$headers = array(
    array(
        'data' => t('Code')
    ),
    array(
        'data' => t('Info')
    ),
    array(
        'data' => t('Points')
    ),
    array(
        'data' => t('Consumed by')
    ),
);
$limit = variable_get('codes_per_page',5);
$query = db_select('loyalty_codes','lc');
$query -> fields('lc',array('code','info','points','uid'))
       -> orderBy('lc.info','ASC')
       -> extend('PagerDefault')
       -> limit($limit);


 //to see all codes for a certain amount of points, just append the number of points to the URL    
 $arg = arg(2);
 if($arg != '' && is_numeric($arg))
 {
    $query->condition('points', $arg);
 }

// Fetch the result set.
 $result = $query->execute();
 $rows = array();
  // Loop through each item and add to the $rows array.
  foreach ($result as $row) {
    $rows[] = array(
        $row->code, 
        $row->info, 
        $row->points, 
        $row->uid, 
    );
  }

  // Format output.
  $output = theme('table', array('header' => $headers, 'rows' => $rows)) . theme('pager');

  return $output;

the $limit variable is set to 5 in the settings form, and it is 5 in the database too.

Anybody who has any idea in why the pager is not showing? perhaps something in the formatting off the output?

Help is very much appreciated!

Was it helpful?

Solution

apparently I can't log in right know because I'm behind a firewall, anyway I seem to have fixed it, stupid mistake though:

the ‘->extend(‘PagerDefault’) extension in the query had to be the first function in the daisy chain. If not there is no error but the function seems to not be called.

$query = db_select('loyalty_codes','lc')
        ->extend('PagerDefault')
        -> fields('lc',array('code','info','points','uid'))
        -> orderBy('lc.info','ASC')
        -> limit(5);//$limit);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top