[support] Using Drupal Pager in D5 Module

Pierre Rineau pierre.rineau at makina-corpus.com
Thu Aug 7 09:16:01 UTC 2008


You have to do your original request like this:

<?php
// Your stuff above

$query = "MY SELECT STATEMENT";
$count_query = "" ; // This is optional, do it if your select query is very complex

$limit = 12242342; // Some integer
// 0 here is the $element var, needed only if you put more than one pager on the same page
$result = pager_query($query, $limit, 0, $count_query /* Leave this to null if you dont use a count_query */);

// Then here treat and display your results

// Then:

// The 0 is the $element above
$form['pager'] = array(
  '#type' = 'markup', // Don't forget this line, else you wont have your pager displayed :)
  '#value' => theme('pager', array() /* Leave a null array here just work */, $limit, 0, array() /* Just put an empty array or ommit the parameter */)
);

// Continue your stuff under
?>

On jeu, 2008-08-07 at 11:07 +0200, Fred Jones wrote:
> I have a custom SQL search and I use pager_query which works nicely.
> But how do I get the paging links to come up? I tried this:
> 
> 		$form['pager'] = array(
> 			'#value' => theme('pager', NULL, 10, 0)
> 		);
> 
> which I see in other modules, but nothing happens. To clarify, this code:
> 
> 		$form[] = array(
> 			'#value' => theme('table', array('Name'), my_module_run_search())
> 		);
> 
> generates the search results, and in my_module_run_search() I call pager_query.
> 
> I am also wondering how the page=1 from the URL gets transferred into
> pager_query, because if I manually add it to the URL, I still get the
> first page.
> 
> Thanks for any pointers!



More information about the support mailing list