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

mukesh.agarwal17’s picture

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