Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By gafir777 on
Hi,
I'm performing a database query that pulls many results from the database, and I would like to know how to display this result in a pagination similar to many administration pages. That is, with a limit number of entries on one single page and a next >> and << previous button at the bottom to get the rest of the entries.
Is there an easy way to make this happen?
Thanks,
Comments
See:
See: http://api.drupal.org/api/function/pager_query/6 and http://api.drupal.org/api/function/theme_pager/6
Use pager_query
Lets say you want to get all the titles of nodes which are of type story... and say you want to display 30 such titles in a page
$sql = "select title, nid from {node} where type = '%s'";
$count_query = "select count(*) from {node} where type = '%s'";
$result = pager_query($sql, 30, 0, $count_query, 'story');
$titles = array();
while ($row = db_fetch_array($result)) {
$rows[''] = l($row['title'], 'node/' . $row['nid']);
$titles[] = $rows;
}
$headers[] = "";
$output = theme('table', $headers, $titles, array("bgcolor" => "#131"));
$output .= theme('pager', NULL, 30);
~~Mukesh~~
Mukesh Agarwal
www.innoraft.com