Gossamer Forum
Home : Products : DBMan : Customization :

short/long display: jump to first/last page

Quote Reply
short/long display: jump to first/last page
Using the short/long display, would it be possible to link to the first and the last page of a multi page results set?
Quote Reply
Re: [peter01] short/long display: jump to first/last page In reply to
I'm sure it would. :-)

In the section marked # create links to previous and next records add
Code:

if ($nh > 1) {
$first = qq~<a href="$db_script_url?$next_url&nh=1"><$font>First</font></a>~;
}
else {
$first = " ";
}
if ($nh < $db_total_hits) {
$last = qq~<a href="$db_script_url?$next_url&nh=$db_total_hits"><$font>Last</font></a>~;
}
else {
$last = " ";
}


Change the # print out the links section to be like the following:

Code:
print qq|
<table width=100%>
<tr><td width=25%>$first</td>
<td width=25%>$previous</td>
<td width=25% align=right>$next</td>
<td width=25% align=right>$last</td></tr>
<tr><td colspan=4 align=center>$list</td></tr>
<tr><td colspan=4 align=center><$font>Record $nh of $db_total_hits</font>
</table>
|;

I haven't tested this at all, not even for syntax errors. But it should be right.

Let me know how it works out. I'll add it to the mods.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] short/long display: jump to first/last page In reply to
Hi JPD,

Thanks very much. Your solution is for the long display, and is greatly appreciated. Unfortunately, my question wasn't clear on this (sorry...), but actually I meant the first and the last page of the short display. I suspect this has to be done in sub query of db.cgi, where the next hits toolbar and $db_next_hits is built. I'll look into it, but maybe you have a quick idea?

thanks and cheers, peter
Quote Reply
Re: [peter01] short/long display: jump to first/last page In reply to
It should do that already. The code

Code:

if ($db_next_hits) { print "<br><$font>Pages: $db_next_hits</font>"; }


includes all of the pages of the search results and should be printed out on the results page. The code is there. Twice. :-)

Or are you talking about the fact that only 7 numbers appear in the page navigation -- the $db_next_hits?

If it's the latter, then you would have to do some editing in db.cgi.

Try this:

Change
Code:

($nh > 1) and ($db_next_hits .= qq~<a href="$db_script_url?$next_url&nh=$prev_hit">[<<]</a> ~);


to
Code:

($nh > 1) and ($db_next_hits .= qq~<a href="$db_script_url?$next_url&nh=1">[First]</a> ~);


and change
Code:
$db_next_hits .= qq~<a href="$db_script_url?$next_url&nh=$next_hit">[>>]</a> ~ unless ($nh == $i);


to
Code:

$db_next_hits .= qq~<a href="$db_script_url?$next_url&nh=$numhits">[Last]</a> ~ unless ($nh == $i);


Again, this is completely untested. :-)


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.

Last edited by:

JPDeni: May 17, 2005, 8:06 AM
Quote Reply
Re: [JPDeni] short/long display: jump to first/last page In reply to
Hi JPD,

Thanks a lot, I'm getting there! The 'jump to first page' link in short display works. The jump to last page doesn't, because the $numhits variable contains the total number of hits (as records), not the total number of pages (sets of for example 10 records if $maxhits is 10). I made a new variable:
Code:
$lastpageshort = int(($numhits/$maxhits) + 1);

and linked to <a href="$db_script_url?$next_url&nh=$lastpageshort">, which works 9 out of 10 times. It doesn't work when the results set is a multitude of 10, like 230 or 240. In the case of 240 hits, in short display you would have 24 pages, but $lastpageshort would link to the 25th page, which doesn't exist. I'm not exactly perl savvy enough to come up with something that works in all cases, and I understand that perl doesn't have a proper rounding function to cope with this in a simple way. Maybe you have an idea?

thanks so much for your time and cheers,
peter

Last edited by:

peter01: May 18, 2005, 2:08 PM
Quote Reply
Re: [peter01] short/long display: jump to first/last page In reply to
Aha! I'm glad you were able to work it out this far. Lots of times this is a team effort. :-)

You could try
Code:

if (($numhits/$maxhits) == int($numhits/$maxhits)) {
$lastpageshort = $numhits/$maxhits;
}
else {
$lastpageshort = int(($numhits/$maxhits) + 1);
}

This time I actually did test it. :-D


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] short/long display: jump to first/last page In reply to
Elegantly simple. Thanks a bunch, it works!

cheers, peter
Quote Reply
Re: [peter01] short/long display: jump to first/last page In reply to
Glad to help. Good luck on your project.

Cheers!


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.