My pager code doesn't work I'm using the following code just to see if the paging works in Drupal 7, but I'm having trouble to set it to work.

$query = db_select('node', 'n')
  -&gt;fields('n', array('nid', 'title'))
  -&gt;extend('PagerDefault')
  -&gt;limit(5);

$headers = array(t('node'), t('Title'));
$rows = array();
$result = $query-&gt;execute();

foreach ($result as $record) {
  $rows[] .= array($record-&gt;nid, $record-&gt;title);
}

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


I'm not so good with PHP, so can someone please tell me what am I doing wrong?
Your code is using the string concatenation operator with an array; you need the assignment operator.

$rows[] = array($record-&gt;nid, $record-&gt;title);




$headers = array(t('node'), t('Title'));
$rows = array();

$nodes = db_select('node', 'n')
  -&gt;fields('n', array('nid', 'title'))
  -&gt;extend('PagerDefault')
  -&gt;limit(5)
  -&gt;execute();

foreach ($nodes as $node) {
  $rows[] = array($node-&gt;nid, $node-&gt;title);
}

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


Depending from which function contains that code, it could also be re-written as follows:

$page = array();
$rows = array();

$nodes = db_select('node', 'n')
  -&gt;fields('n', array('nid', 'title'))
  -&gt;extend('PagerDefault')
  -&gt;limit(5)
  -&gt;execute();

foreach ($nodes as $node) {
  $rows[] = array($node-&gt;nid, $node-&gt;title);
}

$page['table'] = array(
  '#rows' =&gt; $rows, 
  '#header' =&gt; array(t('Node'), t('Title')), 
  '#theme' =&gt; 'table', 
  '#empty' =&gt; t('No content available.'), 
);

$page['pager'] = array(
  '#theme' =&gt; 'pager', 
);

return $page;