Gossamer Forum
Home : Products : DBMan : Customization :

HELP - Displaying Related records in html_record_long

Quote Reply
HELP - Displaying Related records in html_record_long
Salutations one and all! I'm wondering if someone can give me a hand with this little task that I have. I'm almost positive I'm on the right track here, but for some reason its not working.

Basically what I want to do is in the html_record_long routine (in the Short/Long html.pl) have it display other records that "relate" to it. This doesn't entail the relational mod, in that I actually want it to display records from the same .db file. SO, what I have done is set it up so that when the user is entering a record, he/she gets a drop down menu of all the other titles in the database (using the build_select_field_from_db sub). When you enter a record, you can choose if it relates to another record by choosing it from the dropdown. This gets saved in a field called "SubSection." Pretty nifty, eh?

So, the next step is to have the database, when displaying record_long, check the database to see if there are other records in there that have the current records $rec{'Title'} in the SubSection field. I have tried doing this by, basically, jury-rigging the "Display Headlines on Home Page" mod from the Unofficial FAQ. The code I'm putting in html_record_long looks like this:

Code:


open (DB, "<$db_file_name") or &cgierr("error. unable to open db file: $db_file_name.\nReason: $!");

if ($db_use_flock) { flock(DB, 1); }

my @lines = <DB>;

close DB;

my $LASTX = 20;

for ($i=$#lines; $i>=($#lines - $LASTX); $i--) {

chomp $lines[$i];

@data = split(/\|/,$lines[$i]);

next unless ($data[4] eq $rec{'Title'});

$latest .= qq|$data[1]<BR>|;

}

print $latest;



Now, this works little mod works fine as long as I don't include the

next unless ($data[4] eq $rec{'Title'});

But then it, of course, just returns every record in the database... Not just the ones related to the current record. When I leave that line in, the database doesn't return anything. Frown

So, any thoughts would be heavily heavily heavily appreciated. You can check out my html.pl file and .cfg file here and here (respectively).

The code that is supposed to be calling the headlines starts around line 316.

Many thanks in advance, all! Cheers!
Quote Reply
Re: [wretchedhive] HELP - Displaying Related records in html_record_long In reply to
Ok, minor addition here... It does seem to be working... BUT ONLY SOMETIMES (which doesn't make sense in computer world). There are only a couple of articles that have "sub-articles" the way I'm talking about here... One of them is called "Proposal Components" and "How to Present at a Conference." When I call up the "How to Present at a Conference" record, the related articles appear... But when I call up the "Proposal Components" record, they don't.

This makes be very sad. *sniff!*
Quote Reply
Re: [wretchedhive] HELP - Displaying Related records in html_record_long In reply to
This is just a wild guess, but could it have something to do with the "4" in $data[4] ?

I know some perl numbering starts at zero, but, if in this case the that was not true, then you would be comparing to Section and not SubSection, which does seem to include some of the same text.

Just a shot in the dark.
Quote Reply
Re: [joematt] HELP - Displaying Related records in html_record_long In reply to
Hey there Joe, thanks for the tip. data[4] is, indeed, the correct field number for it to work and I know this because, well, I got it to work. The stupid thing is that I didn't really make any changes that I could repeat. I just started playing around with testing it by adding a few lines that printed out $data[4] and $rec{'Title'} next to each other and what not... To make sure they were coming up as the same value. Then I went ahead and started commenting things like the "next" line out... Just seeing what sort of effects it would have.

And then, lo and behold, when I changed it back to the way I (think I) originally had it, it started working. So, I don't know what was wrong before but, well, just in case someone is searching through the threads with a similar problem or question... The above code apparently works... You just have waste a few hours of futility on it before it comes around.

I had no idea Perl was so touchy... Wink

Cheers!