Gossamer Forum
Home : Products : DBMan : Installation :

Next or prev. in sub-long...

Quote Reply
Next or prev. in sub-long...
Hi,
I think, almost everything is possible....

How can I create two links in the html_record_long, that gives the following and previous record from the short tabel in the long version, when a user is in one long record??
Quote Reply
Re: Next or prev. in sub-long... In reply to
If you're still using the ID field, or an equivalent field using default.count, you can do it.

You can increment or decrement the value of $rec{'ID'}, but you get a problem then when you're at the first or last records in the database. To get around that, you check to see if it's the first (first will obviously be 1) or the last (which will be the number in default.count).

Here's how I did it, you might have to modify if to suit your setup:

Code:
open(ID,"$db_id_file_name") or &die("Can't open count file");
$count = <ID>;
close(ID);
$first = 1;
$last = $count;
$id = $rec{'ID'};
if ($id == $first) {$back = $last;}
else {$back = $id--;}
if ($id == $last) {$fwd = 1;}
else {$fwd = $id++;}

Now you have the following variables to use for your navigation buttons:

$first # Obviously 1, the first record in the DB
$last # The value of $count, the last record
$back # Back one record
$fwd # Forward one record

And you'd use them in your record_long call, replacing ID=$rec{'ID'} with ID=$next or $ID=$last.

There's an example here irishfineart.com/bin/db/?view=view&rid=6

Cheers,
adam

ps. I can't get at Carol's website at the moment to check where you should put it, but as far as I remember the subroutine is called html_record_long, and this snippet should be placed just after "my (%rec) = @_;".

[This message has been edited by dahamsta (edited April 25, 1999).]
Quote Reply
Re: Next or prev. in sub-long... In reply to
I don't know. The only way I can think of to do what you want to do is to eliminate the short/long display and change $db_max_hits to 1 in the default.cfg file.

There probably is a way to do what you want, but it would be very complicated.


------------------
JPD





Quote Reply
Re: Next or prev. in sub-long... In reply to
That will work, Adam, if you have consecutive numbers for the ID and if you want to list all the records. But if any records have been deleted in the middle (which means there will be no records for some IDs), if you only want to show the results from a specific search, or if you want the results sorted by any field other than the ID field, it won't work.



------------------
JPD





Quote Reply
Re: Next or prev. in sub-long... In reply to
I'll stay off your turf in future Carol, I always seem to get *something* wrong? Smile

Sorry mart, I should've mentioned that this snippet is really only good for a DB that only the webmaster will be working on, you would have to ensure that there's no gaps, i.e. work on the DB offline. And as Carol says, $fwd and $back are only good for delivering next and last records from the database, *not* the search results. It suits my application, it might not suit yours. Hacking it to deliver the next and last records from the search results would, again as Carol says Smile, be very complicated (although not impossible).

Be a handy hack though Carol, I could see a lot of people would like that one. Possibly you could feed another variable through to the search result page foreach $result (@results), and then pass that through the URL to the long_record.

*Scratch chin thoughtfully* I'm going to have to off in a corner with a copy of db.cgi...

Again sorry if I came across wrong mart.

Cheers,
adam

[This message has been edited by dahamsta (edited April 25, 1999).]
Quote Reply
Re: Next or prev. in sub-long... In reply to
No problem, adam. Keep up the helping. It's amazing how much you learn by offering advice to other folks. You'll find that I go in spurts of giving really bad advice myself. Alex has to come in and tell me that my "fix" won't work. Smile

In order to do this, you'd somehow have to keep track of the previous and next records as you print out the short display in order to pass the keys on to the long display. Maybe this would be a good thing for you to ponder, adam. Smile



------------------
JPD





Quote Reply
Re: Next or prev. in sub-long... In reply to
 
Well, feeding the $next and $last variables through to html_record_long wouldn't be too hard, but you wouldn't be able to continually feed it through from result to result, only from the search results to the *first* record_long.

I think it can be done though, but to repeat (again), it would be pretty complicated, and I'm not going to into it in too much detail. Basically, you would need to run html_record_long with a different .cfg file, and another modified version of the query subroutine.

The .cfg would use the same database, but for the html_record_long one you would have $db_max_hits set to 1 (just in case). Then you would have to copy and modify the query subroutine, calling it query2 or something, and this would deliver the results navigation bar as << and >>, rather than << 1,2,3,4,5 >>, or whatever it does, otherwise you might get a huge string of numbers.

D'you reckon this would work Carol? I might have a look at it over the next week or so, to see if I can get it working.

Cheers,
adam
Quote Reply
Re: Next or prev. in sub-long... In reply to
It might work, adam. Every time I think about how to do this, though, my eyes glaze over. Smile

I had a different idea than yours, but I can't even figure out how to explain it. Go with your idea, adam. See what happens! The worst thing that can happen is that you will learn something!!

------------------
JPD







[This message has been edited by JPDeni (edited April 26, 1999).]