Drupal: Paging made easy

This example shows all the information it takes to implement a simple pager.

$sql = "SELECT nid FROM node n WHERE type = '%s' AND status = %d ORDER BY created DESC";
$res = pager_query($sql, 5, 0, NULL, array('node_type_name', TRUE));

while ($res && ($row = db_fetch_array($res))) {
$node = node_load($row['nid']);
// Display node information here
}

echo theme('pager');

The query can be changed easily, as long as you update pager_query() with the right arguments.

theme('pager') displays the pager widget.

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog