Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

From x to x displayed

Quote Reply
From x to x displayed
   Does anyone know how to put in the search results a message like this:
From x to x links displayed?
I had this with Links 2.0 but I couldnt figure it out with Link SQL!!
Quote Reply
Re: From x to x displayed In reply to
Show us what you did to do that in Links 2, and it shouldn't be too hard to do in Links SQL.

Cheers,

Alex
Quote Reply
Re: From x to x displayed In reply to
Well, in search.cgi, where I had
Code:
# Go through each category of links returned, and build the HTML. Store in hash %link_output.
SETOFLINKS: foreach $setoflinks (sort keys %link_results) {
my $hits = ($#{$link_results{$setoflinks}} + 1) / ($#db_cols+1);
LINK: for ($i = 0; $i < $hits; $i++) {
$link_hits++;
if (($link_hits <= $highrange) && ($link_hits >= $lowrange)) {
%tmp = &array_to_hash ($i, @{$link_results{$setoflinks}});
$link_output{$setoflinks} .= &site_html_link (%tmp) . "\n";
}
}
}

I added a $show++ for counting how many links we are displaying.

Code:
# Go through each category of links returned, and build the HTML. Store in hash %link_output.
SETOFLINKS: foreach $setoflinks (sort keys %link_results) {
my $hits = ($#{$link_results{$setoflinks}} + 1) / ($#db_cols+1);
LINK: for ($i = 0; $i < $hits; $i++) {
$link_hits++;
if (($link_hits <= $highrange) && ($link_hits >= $lowrange)) {
$show++;
%tmp = &array_to_hash ($i, @{$link_results{$setoflinks}});
$link_output{$setoflinks} .= &site_html_link (%tmp) . "\n";
}
}
}

Then in site_html.pl (I donīt use templates) in sub site_html_search_results I have the following code above the &html_print_headers.

Code:
$from = $lowrange;
$to = ($lowrange + $show) - 1;

And finally in the HTML part you add something like:
From $from to $to links are being showed!!


It was working perfecly for me!!!

Thanks again....
Quote Reply
Re: From x to x displayed In reply to
Well, you could do:

my $show = ($link_count > $maxhits) ? $maxhits : $link_count;

What this does is set show equal to the total links returned if that is less then links per page, otherwise set it equal to the links per page. Now just add:

show => $show

to search.cgi around line 166:

# Print out the HTML results.
&site_html_search_results ( { show => $show, ...

You can then use <%show%> wherever you want in the search results template.

Quote Reply
Re: From x to x displayed In reply to
Ok, I figured it out!!
Here is what you have to do!

Where you have:
Code:
my (%link_results, %displayed, $name);
foreach my $hit (@$link_hits) {
$hit = $linkdb->array_to_hash ($hit);
$link_results{$hit->{CategoryID}} .= &site_html_link ($hit, $dynamic);
}

Change for this:
Code:
my (%link_results, %displayed, $name, $showing);
foreach my $hit (@$link_hits) {
$hit = $linkdb->array_to_hash ($hit);
$link_results{$hit->{CategoryID}} .= &site_html_link ($hit, $dynamic);
$showing++;
}

Then, before the call to the search results routine (&site_html_search_results) put this:

Code:
my $from = ($nh > 1) ? (($nh-1) * $mh+1) : 1;
my $to = $from + $showing -1;
my $show = "From $from to $to links being displayed!";

Then then add show => $show to the search results call and you can use <%show%> to diplay this in search results.

That's all!!
Quote Reply
Re: From x to x displayed In reply to
Yeah, thats true.... I will guive it a try..

I didnt used that because the code Alex suggested, allways returned me the maxhits number, even when the total links was higher than maxhits. Wink
Quote Reply
Re: From x to x displayed In reply to
instead of:

Code:
$showing++;

you can put:

Code:
$showing = $linkdb->hits;

i think... not sure.. haven't looked at DBSQL.pm lately..

jerry
Quote Reply
Re: From x to x displayed In reply to
Well widgetz, it didnt worked because
Code:
$showing = $linkdb->hits;
always returned me the total links found, and not how many are being displayed Wink