Gossamer Forum
Home : Products : DBMan : Customization :

Search methods

Quote Reply
Search methods
I am not too fond of perl right now. i need to perform a search based on a select field. For some reason I can only get a keyword search to work. How do I set up the search so you can only select from entries made in a specific record???

eg record name is 'city' and four entries have been added to this field. Toronto, Montreal, New York, London. I want the search to have a select box with all of the entries in the field 'city' .

How can I do this????? If someone can help me I would be forever greatful.

Thanks
Michael
Quote Reply
Re: [kaykills] Search methods In reply to
Quote:
...I would be forever greatful.
WOW!Wink

The default dbman db.cgi has the following sub near the bottom. You can do a search for "build_select_field_from_db" in this customization forum and find the info on how to use it.

sub build_select_field_from_db {
# --------------------------------------------------------
# Builds a SELECT field from the database.

I found this link,

http://www.gossamer-threads.com/...field_from_db;#15175

Not sure how you managed to ALWAYS get a keyword search, maybe because you are not to fond of Perl.

I'll be gone pretty much as soon as I post this reply, but back Monday. Good luck and let us know how it goes. I'm sure we can get you there.
Quote Reply
Re: [joematt] Search methods In reply to
hi,

k.... i assume that I do not have to change anything in the db.cgi file because I am not doing a multiple field search. So this is the code I put in and the select Box appears, but nothing is in it. It is blank. I stress again that I am still a beginner at perl so control your laughter.

sub html_search_options {
# --------------------------------------------------------
# Search options to be displayed at the bottom of search forms.
#
print qq~
<P>
<SELECT>
&build_select_field_from_db("City", "$rec{'City'}")
</SELECT>
~;
}



there are four test entries in the field that I am specifying so I know there is some kind of problem. Once again forever greatfulness will be applied for your help!!Smile
Quote Reply
Re: [kaykills] Search methods In reply to
Been there! Still there really, I just know a thing or two about Perl used in DBman, and it is always surprising me.

I think that the sub was intended to be called from outside the print qq block ( so you need to end it ). Also the sub adds the html form tags for you, so no need to include them. And finally you need to specify the column number in the database that holds the field which will be listed in the select field ( and of course Perl starts counting at zero ) This was not covered in the link I gave you, so no wonder you couldn't get it.

So the way I would write the code is as follows;

Code:
sub html_search_options {
# --------------------------------------------------------
# Search options to be displayed at the bottom of search forms.
#
print qq~
<P>
~; #ends the print qq block

print &build_select_field_from_db(3, "City", "$rec{'City'}"); # just guessing your column number

print qq~
<P>
~; #I put this in just to show you how to start a new print qq block

}

I did NOT test this code, but I looked at a few of my old files and this "looks" correct. FYI and a quick Perl lesson, look at this line in the build_select... sub;

my ($column, $value, $name) = @_;

This is where the sub gets the information sent by this line;

print &build_select_field_from_db(3, "City", "$rec{'City'}");

So looking at these two lines I can see that my code above is WRONG! column is in the right place, but value and name need to be reversed (in the .pl file not in .cgi). Oh well always read the entire post.Smile
Quote Reply
Re: [joematt] Search methods In reply to
ok..... tried that code..... and i reversed the order to Column, Name, Value. Now i get an internal error. Everything looks okay. The field is the third column so I enter 2 as the field. I attached the .pl and the .cfg file if you want to take a quick look. Otherwise I will tinker more with it.
Quote Reply
Re: [kaykills] Search methods In reply to
See the # in front of the print qq? You need to remove that for certain. If that was the only problem, can I laugh now?Smile


Code:
# Search options to be displayed at the bottom of search forms.
# print qq~
<P>
Quote Reply
Re: [joematt] Search methods In reply to
k...... i made the change and I don't get an internal error anymore. i messed with it yesterday but every time I click on the SEARCH link. I get a message where the select box should be. It says

"error building select field: no fields specified! "

can't figure out where to specify the field. I though that was done already.
Quote Reply
Re: [kaykills] Search methods In reply to
OK, I have never used this sub in particular ( I use a similar but different version ), but reading the code it looks like the $column ( where we put the column number ) should be the field name of the column and not the number.

below from db.cgi sub build_select_field_from_db FYI

Code:
for ($i = 0; $i <= $#db_cols; $i++) {
if ($column eq $db_cols[$i]) {
$fieldnum = $i; $found = 1;
last;

Sorry to mislead you.
Quote Reply
Re: [joematt] Search methods In reply to
i drive you crazy.... don't worry about misleading me....... i don't get what you mention..... do I have to modify the sub_build_select_field_from_db ?
Quote Reply
Re: [kaykills] Search methods In reply to
Keeps me on my toes, and it's raining.

Here is the exact change as I see it, to the html.pl file.

Code:
sub html_search_options {
# --------------------------------------------------------
# Search options to be displayed at the bottom of search forms.
#
print qq~
<P>
~; #ends the print qq block

print &build_select_field_from_db("City", "$rec{'City'}", "City"); # I changed the 2 to City I think the qoutes are required ???

print qq~
<P>
~; #I put this in just to show you how to start a new print qq block
}

You should try deciphering the code, it's like a big puzzle.

Last edited by:

joematt: Jun 10, 2003, 7:49 AM
Quote Reply
Re: [joematt] Search methods In reply to
joematt tell me you get paid for this. thanks for the help. it works great now (and in alpha order!)