Pages

Tuesday, March 9, 2010

How to create pagers in drupal

This is a tutorial regarding the creation of pagination in Drupal. Its really hard for the beginner to code the pagination in Drupal. So here is the simple way which i have implemented and is very easy way of bring pagination in Drupal. The code can be any were in Drupal, either in root folder or in the page or in block. Just make sure that your select query is correct.

$headers = array(
  t('Node ID'),
  t('Type'),
  t('Title'),
);

$rows = array();
$sql = "SELECT nid, type, title FROM {node}";
$count = 12;
$query = pager_query($sql, $count);
while ($record = db_fetch_object($query)) {
  $rows[] = array(
    $record->nid,
    $record->type,
    $record->title,
  );
}

$output = theme('table', $headers, $rows);
return $output . theme('pager', $count);

No comments:

Post a Comment