Gossamer Forum
Home : Products : DBMan SQL : Discussion :

3 sections on 1 page

Quote Reply
3 sections on 1 page
Hey

I am trying to get some different database results to show up in 3 sections on my web page.

I use this sub

execute_search_results
Code:
sub {
my $opts = shift;
my $tags = GT::Template->tags;
my $home = $tags->{home};
my @opts = split ('&',$opts);
foreach (@opts) {
next if (!$_);
my ($n,$v) = split('=',$_);
if ($n) {
$home->{cgi}->{$n} = $v || $home->{cgi}->{$n};
}
}
local $home->{cfg} = $home->_load_cfg ($home->{cgi}->{db});
local $home->{db} = $home->{sql}->table ($home->{cgi}->{db});
my $results = $home->search_results;
foreach (keys % $results) { $tags->{$_} = $results->{$_}; }
return $results;
}
On my page I call execute_search_results 3 times.
Code:
<%execute_search_results("db=db&midem_a=Ja")%>
<%if hits%>
<%include sektionA.html%>
<%endif%>
<%execute_search_results("db=db&midem_b=ja")%>
<%if hits%>
<%include sektionB.html%>
<%endif%>
<%execute_search_results("db=db&midem_c=Ja")%>
<%if hits%>
<%include sektionC.html%>
<%endif%>

if I just call it 1 time it works perfect, but when I call execute_search_results 3 times it only shows the results from the first search.

Is it not possible to call the sub execute_search_results 3 times on the same page ?? or is there some thing I don't understand.

I hope somebody can help me. i have searched the forum but I haven't been able to find a solution.

Niels
Quote Reply
Re: [nielsp] 3 sections on 1 page In reply to
In this case, you should change the global template like:

sub {
my ($opts, $session) = @_;
.....
return { results_$session => results->{results}, speed_bar_$session => $results->{speedbar}, hits_$session => $results->{hits} };
}

Now you can show up 3 sessions on the same page by using <%execute_search_results("db=db&midem_a=Ja", 'session_name')%>. Beside the session templates need to be changed as well:

E.g:
<%loop results_A%>
......
<%endloop%>

You can also use <%hits_A%> and <%speedbar_A%> to display number of results and speed bar for session A.

Hope that helps.

TheStone.

B.
Quote Reply
Re: [TheStone] 3 sections on 1 page In reply to
Hi TheStone

Thanks for your answer but...

The code you gave me returns an error:
A fatal error has occured:
Unable to compile 'execute_search_results'. Reason: Can't use bareword ("results") as a HASH ref while "strict refs" in use at (eval 9) line 18.

Any sugestions?

Niels
Quote Reply
Re: [nielsp] 3 sections on 1 page In reply to
Oops...misssing $:

return { results_$session => $results->{results}, speed_bar_$session => $results->{speedbar}, hits_$session => $results->{hits} };

TheStone.

B.
Quote Reply
Re: [TheStone] 3 sections on 1 page In reply to
Hi

The missing $ was also my first gues but this give me the error:

A fatal error has occured:
Can't locate object method "results_" via package "A" at (eval 9) line 17.

when I call it with:
<%execute_search_results("db=db&midem_a=Ja", 'A')%>

any errors in my code for execute_search_results?
Code:
sub {
my ($opts, $session) = @_;
my $tags = GT::Template->tags;
my $home = $tags->{home};
my @opts = split ('&',$opts);
foreach (@opts) {
next if (!$_);
my ($n,$v) = split('=',$_);
if ($n) {
$home->{cgi}->{$n} = $v || $home->{cgi}->{$n};
}
}
local $home->{cfg} = $home->_load_cfg ($home->{cgi}->{db});
local $home->{db} = $home->{sql}->table ($home->{cgi}->{db});
my $results = $home->search_results;
foreach (keys % $results) { $tags->{$_} = $results->{$_}; }
return { results_$session => $results->{results}, speed_bar_$session => $results->{speedbar}, hits_$session => $results->{hits} };
}

Thank for your answer

Niels
Quote Reply
Re: [nielsp] 3 sections on 1 page In reply to
Try this:

return { "results_$session" => $results->{results}, "speed_bar_$session" => $results->{speedbar}, "hits_$session" => $results->{hits} };

TheStone

B.
Quote Reply
Re: [TheStone] 3 sections on 1 page In reply to
Hi again

Now I don't get any errors but it is only the first search that is returned. The other 2 is blank.

Any suggestions?

Niels
Quote Reply
Re: [nielsp] 3 sections on 1 page In reply to
Can you send me the info to access the admin panel in private, I'll have a look?

TheStone.

B.