Sortable Drupal Pagination: pager_query

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


Drupal pagination can be achieved using pager_query API function and tablesort.

I am here mentioning the code snippet that would help create drupal pagination of the output that is sortable with fields.

<?php
  $sql 
'SELECT cid, first_name, last_name, company, city FROM {clients}';
  
$limit 20;
  
$header = array(
    array(
'data' => t('Name'), 'field' => 'last_name''sort' => 'asc'),
    array(
'data' => t('Company'), 'field' => 'company'),
    array(
'data' => t('City'), 'field' => 'city')
  );
  
$tablesort tablesort_sql($header);
  
$result pager_query($sql $tablesort$limit);
  
$rows = array();
  while (
$client db_fetch_object($result)) {
    
$rows[] = array(l($client->last_name.', '.$client->first_name'client/'.$client->cid), $client->company$client->city);
  }
  if (!
$rows) {
    
$rows[] = array(array('data' => t('No client accounts created yet.'), 'colspan' => 3));
  }
  
$output .= theme('table'$header$rows);
  
$output .= theme('pager'NULL$limit0);

  print 
$output;
?>





Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.