Gossamer Forum
Home : Products : DBMan : Customization :

Selectable Fields

Quote Reply
Selectable Fields
Hello from Germany,

I like to setup a Database with a selectable Field. But in this selectable field must be the content of another Database. It look like a relation Database, but it is only to give input in the "Main" Database. How can i do this ?

Best Regards
SChani

Quote Reply
Re: Selectable Fields In reply to
I'm not quite sure what you mean. Can you give me an example?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Selectable Fields In reply to
Hello JPD,

i have a simple Database with 25 Fields. One is a selectable Field called Category. When i add a new category, i must change it in the default.cfg file. Thats not posible for the user. Now i like to make a 2nd Database, only with this Category´s and use it in the "Main" Input Form as a selectable Field.

i hope you can understand my english whit bavarian slang.

Best Regards

Quote Reply
Re: Selectable Fields In reply to
I'm not positive but I think this thread may be relating to what you want to do.

http://www.gossamer-threads.com/scripts/forum/resources/Forum12/HTML/002866.html

Topic: Can you have a Select & Text name for same field?

There are also some other references in the FAQ noted below under "Fields" and "Files / Records".

Hope this helps

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Selectable Fields In reply to
You can have the script pull the values from the database. Instead of

print &build_select_field("FieldName",$rec{'FieldName'})

use

print &build_select_field_from_db("FieldName",$rec{'FieldName'})

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Selectable Fields In reply to
Sorry JPD, but i did not understand.

Where can i integrate this Code ?

Is it not nessesary to integrade a new routine in the db.cgi file to call the List of records from the 2nd Database ?

Best Regards

Quote Reply
Re: Selectable Fields In reply to
place it in the html.pl file e.g.

<TR><TD ALIGN="Right" VALIGN="center"><$font>Make: </FONT></TD>
<TD VALIGN="TOP"><$font>|; print &build_select_field_from_db ("Make", "$rec{'Make'}"); print qq|</font></TD></TR>

HTH, Brian

Quote Reply
Re: Selectable Fields In reply to
This Code is great, but it not use the Input from a 2nd Database. Thats the problem. I can not edit the content of the selectable Field (like in FileMaker).

Best Regards

Quote Reply
Re: Selectable Fields In reply to
Now i used the

|; print &build_select_field_from_db ("Make", "$rec{'Make'}"); print qq|

Code in my Database, but i have trouble with the | Key in the selectable field



Quote Reply
Re: Selectable Fields In reply to
Do you want multiple selections?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Selectable Fields In reply to
Hello JPDeni,

No, i not need multible selection. My major problem is that i like to have the content in the selectable Field (Choice List) from another Database.

Now with the script, the content commes from the own Database.

Thanx for help.
Schani

Quote Reply
Re: Selectable Fields In reply to
Okay. Now I got it. (Sometimes I'm a little slow. Smile

In your .cfg file, add a variable to define the path to the external database:

$db_other_file_name = $db_script_path . "/other.db";

Add the following subroutine to db.cgi:

Code:

sub build_select_field_from_other_db {
# --------------------------------------------------------
# Builds a SELECT field from an external database.
# Parameters are
# the column to which the value will be written -- $column
# a default value -- $value
# The number of the field in the other .db file that holds the
# values you want in your select field -- $fieldnum

my ($column, $value, $fieldnum) = @_;
my (@fields, $field, @selectfields, $selected, @lines, $line, $output, $found);

for ($i = 0; $i <= $#db_cols; $i++) {
if ($column eq $db_cols[$i]) {
$found = 1;
last;
}
}
if (!$found) {
return "error building select field: no fields specified!";
}

open (DB, "<$db_other_file_name") or &cgierr("Error in build_select_field_from_other_db.
Unable to open $db_other_file_name. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
if (!(grep $_ eq $fields[$fieldnum], @selectfields)) {
push (@selectfields, $fields[$fieldnum]);
}
}
close DB;

$output = qq|<SELECT NAME="$column"><OPTION>---|;
foreach $field (sort @selectfields) {
if ($value eq $field) { $output .= "<OPTION SELECTED>$field"; }
else { $output .= "<OPTION>$field"; }
}
$output .= "</SELECT>";
return $output;
}
To use it --

|; print &build_select_field_from_other_db("FieldName",$rec{'FieldName'},#); print qq|

Where # is the number of the field in the other database you want to use.

Sorry for the confusion. Smile

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Selectable Fields In reply to
Great,
this looks fine. Thanx für this Code.
But a CGI Checker locade a syntax Error in this line:
my ($column, $value, $fieldnum) = @_;

where can by the Error ? Ore must i change the @ with the field Number of the 2nd Database ?

Christian



Quote Reply
Re: Selectable Fields In reply to
That line should be just fine.

Often the syntax checkers don't give you the correct line where the problem is. All you can be sure of is that the problem is either on that line or before it.

My Perl compiler says that the subroutine syntax is correct.


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Selectable Fields In reply to
Sorry Sorry Sorry,
for my late response. I was on holiday for a week. I checked again your code and i still found my problem with it.
I had a problem with copy and past from the forum to Adobe Golive on Mac. I checked the blank letters an it work.

Your script work fine and i think DBMan is already a relational Databae ;-).

Thanks for your help and best regards from Munich.

Schani

Quote Reply
Re: Selectable Fields In reply to
I know this is a old post, but I wanted to do something similar.

Instead of grabbing a select field off of another databse, I'd like to grab the value of a text field (called "Email") and place it into a variable and possibly be able to print it. How might I do this?

Regards,



Michael DeLong
Quote Reply
Re: Selectable Fields In reply to
Generating a select field from a database entries:

To produce a select list of unique values in the database use:

print &build_select_field_from_db ('Column', $rec{'Column'});

A good example of when you would want to use this is for your own search form.

You could then only display the entries which are actually contained within a particular select field.

This and so many other Frequently Asked Questions can be found in the FAQ noted below. That particular reference can be located under "Fields" and then "Working with Selects"


Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/