[ic] query tag, more condition

Mark Johnson mark at endpoint.com
Thu Aug 17 07:12:05 EDT 2006

Andrew N wrote:
> Hello.
> When using the query tag with the more option, is there a way I can
> tell if there are more results than my ml are going to be returned and
> check that in a condition?
> I know that I could issue a separate sql command with a count(*) and
> than check that number, but I want to avoid the overhead of issuing a
> separate query.

A generalization of this issue comes up somewhat frequently, in that
within a more-list pagination there exists a need to know something
about the query results as a whole. Another simple example would be
displaying aggregate totals for numeric fields within each page, while
still partitioning the results into manageable chunks.

You can get access to the full result set in embedded perl using the
hashref or arrayref parameters within [query]. My general methodology is
to construct a [calc] block within [on-match] that performs whatever
aggregate work I'd like to do on the set, store those values in scratch,
and then put in conditional code to keep from resetting the scratch
values when the page loads from a more-list scan.

So, for your above request, you could have something like the following:

> [query
> 	list=1
> 	more=1
> 	ml=10
> 	arrayref=aggregate
> 	...
> ]
> [on-match]
> 	[calcn]
> 		return if $CGI->{mv_more_ip};
> 		$Scratch->{have_more_than_ml} =
> 			@{ $Tmp->{aggregate} } > 10;
> 		return;
> 	[/calcn]
> [/on-match]
> [list]
> ...

This is a somewhat contrived example because Interchange gives you the
full matches inside a [more-list] with [match-count], but any result-set
analytics beyond such would need to have access to the full set, and
above demonstrates how to get at it.


Mark Johnson
End Point Corporation

More information about the interchange-users mailing list