Gossamer Forum
Home : Products : DBMan : Customization :

Adding 1 + var to "Link by title field" SOLVED!

Quote Reply
Adding 1 + var to "Link by title field" SOLVED!
Hi,

Well, I didn't have much response to my previous posts; I guess I'm not explaining myself right, sorry...

Meanwhile, I found something that does what I want, from the Unofficial Help/FAQ:


sub list_titles {
#----------------------------------
my ($cat_field,$cat_name,%titles,$title,@fields);
my $fieldnum1 = 4; # Change this to the number of your Category field
my $fieldnum2 = 5; # Change this to the number of your Title field
open (DB, "<$db_file_name") or &cgierr("error in list_titles. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if ($fields[$fieldnum1] eq $in{$db_cols[$fieldnum1]}) {
$titles{$fields[$fieldnum2]} = $fields[$db_key_pos];
}
}
close DB;

$cat_field = &urlencode($db_cols[$fieldnum1]);
$cat_name = &urlencode($in{$db_cols[$fieldnum1]});
foreach $title (sort keys %titles) {
print qq|
<a href="$db_script_link_url&$cat_field=$cat_name&$db_key=$titles{$title}&ww=on&view_records=1">$title</a> |;
}
}


You can see how it works at:

http://www.plurinet.com/cgi-local/produto/index.cgi?db=default&uid=default&marca=Polaroid&ID=10&submarca=Kids&ww=on&view_records=1

(it's in Portuguese)

This does what I want, but I need to extend it further, so the subroutine checks a 3rd field...

I have the following fields:

1-Type
2-Brand
3-SubBrand
4- Model

my $fieldnum1 = 1; # Type
my $fieldnum2 = 2; # Brand

And this works halfway:

It lists all the models from BrandX & TypeX; I need to include the SubBrand field on this subroutine... is it possible?

I tried to add

my $fieldnum3 = 3; # subModel

, but I don't know what to do next for it to work...

Also, I need exclude the current record being displayed from the list that the above subroutine returns...

I'm sorry if I'm not being clear, but my Perl knowledge is very limited, and I'm pretty desperate, at this time...

Thank you for any help,

Gustavo Melo

Quote Reply
Re: Adding one more variable to "Link by title field" In reply to
Better to add a REPLY to your original Thread to bring it back to the top of the forum and also reduce duplication within the forums.

Regards,

Eliot Lee
Quote Reply
Re: Adding one more variable to "Link by title field" In reply to
Yes, you're right about that... at least in part... You see, it's very difficult to me to write in a foreign language (English) about something (Perl) that isn't clear to me, not even in my mind... and since I didn't get any responses to my previous posts, I guessed that the reason for that was lack of clarity ;), hence a new post about it...

But I'll copy the contents to this one, and delete the old anyway...

Best,

Gustavo Melo

Quote Reply
Original post In reply to
***Original Post***


Hi,

I'm trying to mix the long and short diplays;

Maybe an example to try to explain:

Imagine a database of sunglasses;
I have fields for brand & model;
The output consists of a picture of the model

I would like, when doing a "list all" for a certain brand, that:

- the first record (model) would appear right away
- a list of the other models for that brand that would serve as menu, but that exclude the current record, being displayed.

Something like this:

1|Armani|model1
2|Armani|model2
3|Armani|model3
4|Armani|model4
5|Armani|model5

When doing a search for Armani, I would get:

|--------|
| Model1 |
|--------|

Model2 | Model3 | Model4 | Model5

I hope you understand what I am looking for...

By the way, congrats to all, especially to the veterans, for this excellent resource!

Best,

Gustavo Melo


Quote Reply
Re: Original post In reply to
You seem to be having more problems than this Mod, because I get the DBMAN Encountered an Internal Error message. I would suggest turning on de-bugging to see what errors you get.

Also, all you really have to do is add conditional statement that checks the current $rec{'ID'} like:

Code:

if ($rec{'ID'}) {
$next;
}


Regards,

Eliot Lee
Quote Reply
Re: Original post In reply to
The link above is working now... I was trying something and forgot to upload the corrected HTML.PL file, sorry...

Where would I insert that conditional statement?... I tried


if ($rec{'ID'} eq $in{'ID'}) { $next;}
print qq|
<a href="$db_script_link_url&$cat_field=$cat_name&$db_key=$titles{$modelo}&submarca=$submarca&ww=on&view_records=1"><font face="Arial" size="3" color="#204B31">$modelo</font></a>
|;


But it doesn't do anything... also, is it possible to add a 3rd field to the subroutine, so it lists all models (except the one currently being displayed) for Brand X AND SubBrand Y

Thank you for your reply, and sorry for being so dumb about this...

Best,

Gustavo Melo

Quote Reply
Re: Original post In reply to
I gave an example of codes you could use. I did not state that they would work. I clearly qualified the codes by stating that it was an example.

Regards,

Eliot Lee
Quote Reply
Re: Original post In reply to
Hi,

I gave an example of codes you could use. I did not state that they would work. I clearly qualified the codes by stating that it was an example.

Yes Eliot, I realize that, and thanks for the help! The problem is that I don't know enough Perl to understand what to do with that code, or where to put it Blush (I bought a book, I'm waiting for it, though...)

If you could give me a little more help about this I would be forever grateful!

Thanks

Gustavo Melo

Quote Reply
Re: Original post In reply to
I think if Eliot had a solution he would have posted it.

He does tend to like to confuse people at times.

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Original post In reply to
I was providing a SUGGESTION, LOISC!
Quote Reply
Re: Original post In reply to
Please, guys, don't fight because of my ignorance... I'll try to find out the solution to this myself...

Best,

Gustavo Melo

Quote Reply
Problem solved! In reply to
Well,

It took me a long time and A LOT of tries, but I finally have what I was looking for...

I used the following sub-routine, and used what Eliot suggested (highlighted in blue):


my ($cat_type,$cat_field,$cat_name,%titles,$modelo,@fields);
my $fieldnum1 = 2; # Change this to the number of your Category field
my $fieldnum2 = 3; # Change this to the number of your Title field
open (DB, "<$db_file_name") or &cgierr("error in list_titles. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if ($fields[$fieldnum1] eq $in{$db_cols[$fieldnum1]}) {
$titles{$fields[$fieldnum2]} = $fields[$db_key_pos];
}
}
close DB;
$cat_type = &urlencode($db_cols[$fieldnum1]);
$cat_field = &urlencode($db_cols[$fieldnum1]);
$cat_name = &urlencode($in{$db_cols[$fieldnum1]});

foreach $modelo (sort keys %titles) {

if ($modelo eq $rec{'modelo'}) {
$next;
}

else {
print qq|<a href="$db_script_link_url&$cat_field=$cat_name&$db_key=$titles{$modelo}&ww=on&view_records=1">$modelo</a> |;
}
}


This does exactly what I want: returns all the records in the db that match the Brand of the one being displayed, and excludes it (current record) from the output...

Thanks Eliot for pointing me in the right direction. And, again, please don't fight because of this!

Peace,

Gustavo Melo

Quote Reply
Re: Problem solved! In reply to
Glad you figured it out.

See that my post was edited by LoisC, the moderator! grr...