Using the short/long display, would it be possible to link to the first and the last page of a multi page results set?
May 17, 2005, 6:55 AM
Veteran / Moderator (8669 posts)
May 17, 2005, 6:55 AM
Post #2 of 8
Views: 3837
I'm sure it would. :-)
In the section marked # create links to previous and next records add
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:
<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.
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.
May 17, 2005, 7:45 AM
Novice (15 posts)
May 17, 2005, 7:45 AM
Post #3 of 8
Views: 3829
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
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
May 17, 2005, 8:05 AM
Veteran / Moderator (8669 posts)
May 17, 2005, 8:05 AM
Post #4 of 8
Views: 3843
It should do that already. The 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
($nh > 1) and ($db_next_hits .= qq~<a href="$db_script_url?$next_url&nh=$prev_hit">[<<]</a> ~);
to
($nh > 1) and ($db_next_hits .= qq~<a href="$db_script_url?$next_url&nh=1">[First]</a> ~);
and change
to
$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.
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.
May 18, 2005, 2:07 PM
Novice (15 posts)
May 18, 2005, 2:07 PM
Post #5 of 8
Views: 3798
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:
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
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
May 18, 2005, 2:28 PM
Veteran / Moderator (8669 posts)
May 18, 2005, 2:28 PM
Post #6 of 8
Views: 3807
Aha! I'm glad you were able to work it out this far. Lots of times this is a team effort. :-)
You could try
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.
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.
May 18, 2005, 2:56 PM
Veteran / Moderator (8669 posts)
May 18, 2005, 2:56 PM
Post #8 of 8
Views: 3779
Glad to help. Good luck on your project.
Cheers!
JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Cheers!
JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.