Gossamer Forum
Home : Products : DBMan : Installation :

Category

Quote Reply
Category
Hi,

I need to have the following.

I have categories which I need to enter when adding to the database. I am going to
use the
Code:
print &build_select_field ("Category", "$rec{'Category'}");
. This way I can select a category, i.e. Sony, Panasonic, JVC, etc..

Now, the list of all the records which I will be adding from, is not sorted by category. So next to each item number there is a number referencing to the category, and I have a paper with all the numbers and what they belong to. So I look for that number (let's say 1), I see on my paper that 1 = Sony, then I go back to the Add Record form, choose from the drop down menu for the category "Sony".

So here is what I want to do.

<OPTION VALUE="Sony">1</OPTION>
<OPTION VALUE="Panasonic">2</OPTION>

As you can see I will be choosing the number from the drop down list, but the value
is something else. This will be much easier for me.

Please tell me how I can do this.

I greatly appreciate it.

------------------
Thanks
JFrost

Quote Reply
Re: Category In reply to
I had a client who wanted something similar, so I created a "fancy select field."

Code:
sub build_fancy_select_field {
my $field = $_[0];
my $compare = $_[1];

my %selector = (
'field1' => [ ['---','Select'],
['real value','visible value'],
['real value','visible value'],
['real value','visible value'],...
['real value','visible value']
],
'field2' => [ ['---','Select'],
['real value','visible value'],
['real value','visible value'],
['real value','visible value'],...
['real value','visible value']
]
);

$output = qq|<SELECT NAME="$field">\n|;
$i = 0;
while ( $selector{$field}[$i][0] ) {
$selector{$field}[$i][0] eq $compare ?
($output .= qq|<OPTION VALUE="$selector{$field}[$i][0]" SELECTED>$selector{$field}[$i][1]\n|) :
($output .= qq|<OPTION VALUE="$selector{$field}[$i][0]">$selector{$field}[$i][1]\n|);
++$i;
}

if ($i) { $output .= "</SELECT>"; }
else { $output = "Incorrect field definition"; }
return $output;
}

Then call the subroutine by

print &build_fancy_select_field("field1",$rec{'field1'});


------------------
JPD
Quote Reply
Re: Category In reply to
Hi,

Fist of, I would like to really thank you AGAIN!

Secondly, can you please tell me where to put this awesome mod, and how do I modify it. What I am asking is, let's say I want the value to be "Sony", and I just want to see "1", where and how would I do this.

I would again like to thank you.

------------------
Thanks
JFrost

Quote Reply
Re: Category In reply to
Did I forget to tell you where to put it? Wink

You can stick it just about anywhere. Maybe the best place would be in your .cfg file, just before the section that starts with:

# Build up some variables from your definitions. Internal use only.

As for how to modify it, here's an example, using the data you gave us:

Code:
my %selector = (
'Category' => [
['---','Select'],
['Sony','1'],
['Panasonic','2'],
['SomethingElse','3'],
['TheLastOne','visible value']
]
);

Just replace the definintion for the %selector variable with what I have above, filling in more items, of course. You don't need the "field2" definition, if you only have one field.


------------------
JPD
Quote Reply
Re: Category In reply to
It is working (great!) and a first answer for my question. I have now in my search_form a field with visible values and real values in the code.

But
Now what i want is that in the display result after searching, not the code is seen, but the visible value.
How have I to realise it?
Quote Reply
Re: Category In reply to
If you've only got a few things, it would probably be best to use

Code:
if ($rec{'FieldName'} eq "A") {
print "Apple";
}
elsif ($rec{'FieldName'} eq "B") {
print "Book";
}

If you have a lot of possibilities, you can use a hash to print them out.

Somewhere (probably in your .cfg file) create a translation of the codes like--

Code:
%FieldName = ( A => Apple,
B => Book,
C => Cat,
D => Dog
);

Then, when you go to print it out, use

$FieldName{$rec{'FieldName'}};


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


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