[drupal-devel] Question on use of theme_pager() and related functions
Is there a good example somewhere illustrating the correct use of calls to theme('pager',....)? I'm trying to use this function, and I've actually got it working except for one issue: I don't know how to tell it the actual number of rows that were returned from my database query. I see the "tags" array that can be passed, and it *looks* as if that would be the right thing to do. But node.module, statistics.module, and all the others I can find in Drupal core seem to always pass NULL for that parameter to theme_pager(). So I'm led to conclude that somehow theme_pager() gets this information from elsewhere in the "normal" case. The example modules, as luck would have it, don't use this feature. Suggestions? Scott -- ------------------------------------------------------------------------------ Scott Courtney | "I don't mind Microsoft making money. I mind them scott@4th.com | having a bad operating system." -- Linus Torvalds http://4th.com/ | ("The Rebel Code," NY Times, 21 February 1999) | PGP Public Key at http://4th.com/keys/scott.pubkey
The function creates its own query to count records by rewriting yours. Usually that's fine but there are cases where it's not accurate. When that happens there's a third parameter you can pass that will be a query that returns the number of records you're dealing with. On 5/2/05, Scott Courtney <scott@4th.com> wrote:
Is there a good example somewhere illustrating the correct use of calls to theme('pager',....)?
I'm trying to use this function, and I've actually got it working except for one issue: I don't know how to tell it the actual number of rows that were returned from my database query.
I see the "tags" array that can be passed, and it *looks* as if that would be the right thing to do. But node.module, statistics.module, and all the others I can find in Drupal core seem to always pass NULL for that parameter to theme_pager(). So I'm led to conclude that somehow theme_pager() gets this information from elsewhere in the "normal" case.
The example modules, as luck would have it, don't use this feature.
Suggestions?
Scott
-- ------------------------------------------------------------------------------ Scott Courtney | "I don't mind Microsoft making money. I mind them scott@4th.com | having a bad operating system." -- Linus Torvalds http://4th.com/ | ("The Rebel Code," NY Times, 21 February 1999) | PGP Public Key at http://4th.com/keys/scott.pubkey
On Monday 02 May 2005 22:56, Earl Dunovant wrote:
The function creates its own query to count records by rewriting yours. Usually that's fine but there are cases where it's not accurate. When that happens there's a third parameter you can pass that will be a query that returns the number of records you're dealing with.
How does it even know my query, though? I'm looking at the documentation here: http://drupaldocs.org/api/4.6/function/theme_pager and I don't even see that the query is known to the function. I'm using the function pager_query() to actually execute my query. I looked at the released version of node.module, and tried to do things the same way. But I've overlooked something, clearly. Thanks for your reply, and I'm sorry if I'm being dense. I've not used this set of functions before. Scott -- ------------------------------------------------------------------------------ Scott Courtney | "I don't mind Microsoft making money. I mind them scott@4th.com | having a bad operating system." -- Linus Torvalds http://4th.com/ | ("The Rebel Code," NY Times, 21 February 1999) | PGP Public Key at http://4th.com/keys/scott.pubkey
Scott Courtney wrote:
Is there a good example somewhere illustrating the correct use of calls to theme('pager',....)?
I'm trying to use this function, and I've actually got it working except for one issue: I don't know how to tell it the actual number of rows that were returned from my database query.
what do you need that "actual number of rows that were returned from my database query" for? the meaning of theme_pager() is to split an resultset of x rows into pages of $limit rows. if you really really need the total number of rows, check global $pager_total; init'ed in pager_query(), used in theme_pager().
I see the "tags" array that can be passed, and it *looks* as if that would be the right thing to do.
no - the $tags param is used change the pager strings 'first page', 'previous page', 'next page', and 'last page'. -- ax I'm tired, Trinity. I tired of this war. I'm tired of fighting. I'm tired of this ship, of being cold, eating the same God-damn goop everyday. But most of all, I'm tired of that jack-off and all of his bullshit. Surprise ass-hole. I bet you never saw this coming, did you? God, I wish I could be there, when they break ya. I wish I could walk in just when it happens. So right then, you'd know it was me. - Cypher, The Matrix
On Tuesday 03 May 2005 12:39, Axel Kollmorgen wrote:
I'm trying to use this function, and I've actually got it working except for one issue: I don't know how to tell it the actual number of rows that were returned from my database query.
what do you need that "actual number of rows that were returned from my database query" for? the meaning of theme_pager() is to split an resultset of x rows into pages of $limit rows.
It's not that *I* need it, but rather that theme_pager() needs it and doesn't seem to be getting it. I can retrieve it easily from db_num_rows(). I wasn't aware of the global variable, but someone pointed it out to me off list. So now I just need to trace and find out why it's not getting set. When I wasn't aware it existed, I was on a wild goose chase looking for some trick in the parameters that was supposed to pass this data. :-)
if you really really need the total number of rows, check
global $pager_total;
init'ed in pager_query(), used in theme_pager().
That's where I'm headed next.
I see the "tags" array that can be passed, and it *looks* as if that would be the right thing to do.
no - the $tags param is used change the pager strings 'first page', 'previous page', 'next page', and 'last page'.
Mea culpa -- I figured that out right after I posted to the list (isn't that always the way?). Time to dive into that global variable. My table only has two rows *total*, so there's no way the pager should be thinking 900+. I'm doing something bogus here. Scott -- ------------------------------------------------------------------------------- Scott Courtney Drupal user name: "syscrusher" http://drupal.org/user/9184 scott at 4th dot com Drupal projects: http://drupal.org/project/user/9184 Sandbox: http://cvs.drupal.org/viewcvs/drupal/contributions/sandbox/syscrusher
participants (4)
-
Axel Kollmorgen -
Earl Dunovant -
Scott Courtney -
Syscrusher