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!
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!
'#type' => 'markup', // Don't forget this line, else you wont have your pager displayed :)
No, actually that is optional, as that is the default type. This code for example:
$form[] = array( '#value' => '<fieldset><legend>Search Results</legend>' );
works fine.
But I don't see how your code is different than mine. I have:
$form[] = array( '#value' => mymodule_run_search() ); $form['pager'] = array( '#value' => theme('pager', NULL, 10, 0) );
which displays first the search results and then the pager (or I want it to). And in mymodule_run_search I have this:
$sql = "SELECT nid, title, teaser FROM {node_revisions} WHERE body like '%%%s%' ". 'group by nid order by nid'; $r = pager_query($sql, 10,0,null,$_GET['title_text']);
and then some code to format the results. The search results part works great--the only thing NOT working is the pager.
Thanks.