[ic] SQL + search_region

Jamie Neil jamie at versado.net
Wed May 26 12:21:35 EDT 2004


Jamie Neil wrote:

> Mike Heins wrote:
> 
>> Sounds like mostly you want to pre-do the search with SQL, and
>> then display it with the search-region. This can easily be done
> 
> 
> That's exactly what I want to do. That way I can use a single search 
> results template and code the searches as action maps (somehow feels 
> neater than putting the sql in the pages).
> 
>> by formatting a $Search->{labelname} object, then passing it
>> on with [search-region label=labelname]. I believe you want
>> to have at least:
>>
>>     my $ary = [ [ 'return1', 'return2', ] ];
>>     my $n = scalar @$ary;
>>     $Search->{$label} = {
>>         matches => $n,
>>         mv_results => $ary,
>>         mv_matchlimit => 20,
>>         mv_field_names => [ 'field1', 'field2', ],
>>     };
>>
> 
> Hmm - I'm a bit fuzzy on arrayrefs and hashrefs. Could you give an 
> simple example using the query tag, or is it as simple as just 
> substituting $ary for a query tag and plugging the return field names 
> into the array at the bottom?

OK, I've got it to work this far:

[query arrayref=results sql=|SELECT sku,description FROM products|][/query]
[tmp count]
[perl]
my $results = $Tmp->{results};
my $count = scalar @$results;
$Search->{results} = {
   matches => $count,
   mv_results => $results,
   mv_matchlimit => 10,
   mv_field_names => [ 'sku', 'description', ],
};
[/perl]
[/tmp]

[on-match]
[more-list]
Results [matches] of [match-count]
[more]
[/more-list]
[/on-match]

[search-region label=results]
[search-list]
<p>[item-code] - [item-param description]</p>
[/search-list]
[/search-region]

However the more list has a blank reference to the search results:

/scan/MM=:10:19:10.html?mv_more_ip=1&mv_nextpage=testpage

Maybe I'm going about this all wrong. What I want to achieve is a single 
template that I can use for displaying IC or SQL search results, so that 
if I need to change the layout I need only edit one file.

Should I just resign myself to having more than one template - one for 
IC search and one for SQL?

-- 
Jamie Neil | <jamie at versado.net> | 0870 7777 454
Versado I.T. Services Ltd. | http://versado.net/ | 0845 450 1254


More information about the interchange-users mailing list