Hello all,
I've been trying to fashion an 'internal search' mod that works with JPDeni's original short/long mod. In short, when a user views the long version of a record, this internal search mod displays abbreviated versions of other records, such as "Other articles by this author" or "This week's newest records." Clicking on one of these related records brings up its long version.
I'm not a Perl genius. Using what I've learned about DBMan from this forum, I was able to concoct a solution, but it suffers from at least one drawback: I intended the mod to isolate temporary %in values for our internal search, and then replace the original %in values (as called in the url) so that the page will load as expected. Instead, the %in values seem to be added to each other, muddying the water, so to speak.
In other words, the only way to use this mod successfully is to make sure that it executes after the main record and associated page numbering, etc. has been displayed. Putting it before the main record threatens to replace the expected %in values with the temporary, internal %in values, screwing up results and related links.
I'd like to improve the mod and make it usable anywhere on the page. So I turn again to this community for advice. If you can tighten up or repair the following work, I'd be most grateful.
Here's the mod as it stands:
# key-value pairs to search on, and call the new subroutine.
%in_values = ("Key","value","sb",1,"so","descend","mh",1);
print &internal_search(%in_values);
sub internal_search {
# --------------------------------------------------------
# Performs another db query to produce a new display
# of records within and separate from the current results.
my (%inhash) = @_;
my $output;
# attempt to transfer the current %in values to a
# temporary holding hash
%current_in = %in;
undef %in;
# creates new, temporary %in with values from %inhash
while (($key, $value) = each (%inhash)) {
push(@invalues, $key, $value);
}
%in = @invalues;
# call the search
my ($status2, @hits2) = &query("view");
my ($numhits2) = ($#hits2+1) / ($#db_cols+1);
# if results were found, send them to html_record_brief
# (a new subroutine) for display
if ($status2 eq "ok") {
for (0 .. $numhits2 - 1) {
$output .= &$html_record_brief (&array_to_hash($_, @hits2));
++$rec_count;
}
}
# attempt to restore the current %in values
undef %in;
%in = %current_in;
return $output;
}
Thanks for looking,
ecn
I've been trying to fashion an 'internal search' mod that works with JPDeni's original short/long mod. In short, when a user views the long version of a record, this internal search mod displays abbreviated versions of other records, such as "Other articles by this author" or "This week's newest records." Clicking on one of these related records brings up its long version.
I'm not a Perl genius. Using what I've learned about DBMan from this forum, I was able to concoct a solution, but it suffers from at least one drawback: I intended the mod to isolate temporary %in values for our internal search, and then replace the original %in values (as called in the url) so that the page will load as expected. Instead, the %in values seem to be added to each other, muddying the water, so to speak.
In other words, the only way to use this mod successfully is to make sure that it executes after the main record and associated page numbering, etc. has been displayed. Putting it before the main record threatens to replace the expected %in values with the temporary, internal %in values, screwing up results and related links.
I'd like to improve the mod and make it usable anywhere on the page. So I turn again to this community for advice. If you can tighten up or repair the following work, I'd be most grateful.
Here's the mod as it stands:
Code:
# somewhere in sub html_record_long, create new # key-value pairs to search on, and call the new subroutine.
%in_values = ("Key","value","sb",1,"so","descend","mh",1);
print &internal_search(%in_values);
sub internal_search {
# --------------------------------------------------------
# Performs another db query to produce a new display
# of records within and separate from the current results.
my (%inhash) = @_;
my $output;
# attempt to transfer the current %in values to a
# temporary holding hash
%current_in = %in;
undef %in;
# creates new, temporary %in with values from %inhash
while (($key, $value) = each (%inhash)) {
push(@invalues, $key, $value);
}
%in = @invalues;
# call the search
my ($status2, @hits2) = &query("view");
my ($numhits2) = ($#hits2+1) / ($#db_cols+1);
# if results were found, send them to html_record_brief
# (a new subroutine) for display
if ($status2 eq "ok") {
for (0 .. $numhits2 - 1) {
$output .= &$html_record_brief (&array_to_hash($_, @hits2));
++$rec_count;
}
}
# attempt to restore the current %in values
undef %in;
%in = %current_in;
return $output;
}
Thanks for looking,
ecn