The SQL command is 'Select Distinct' when you want only the unique items in a field.
I'm not sure how that translate for you in DBManSQL 2 -- I'm still struggling with 1.02 which the select statement comes from db.cgi and works for me in my build_select_from_db code. which reads:
sub build_select_field_from_db {
# ---------------------------------------------
# Builds a select list from fields in the database.
#
my ($column, $value, $name) = @_;
my (@fields, $field, %selectfields, $ouptut, $fieldnum, $found);
# Make sure this is a valid field.
(grep $_ eq $column, @db_cols) or return "error building select field: no fields specified!";
$name = $name || $column;
my $query = qq!
SELECT DISTINCT $column FROM $db_table
!;
my $sth = $DBH->prepare ($query) or &cgierr("Unable to query database. Reason: $DBI::errstr. Query: $query");
$sth->execute or &cgierr("Unable to query database. Reason: $DBI::errstr. Query: $query");
# Make a select list out of those names.
$output = qq|<SELECT NAME="$name"><OPTION>---|;
while (($field) = $sth->fetchrow_array) {
($value =~ /^\s*$field\s*/) ?
($output .= "<OPTION SELECTED>$field\n") :
($output .= "<OPTION>$field\n");
}
$output .= "</select>";
$sth->finish;
return $output;
}
Maybe that will help you!
Lynette
Hollister, Ca
I'm not sure how that translate for you in DBManSQL 2 -- I'm still struggling with 1.02 which the select statement comes from db.cgi and works for me in my build_select_from_db code. which reads:
sub build_select_field_from_db {
# ---------------------------------------------
# Builds a select list from fields in the database.
#
my ($column, $value, $name) = @_;
my (@fields, $field, %selectfields, $ouptut, $fieldnum, $found);
# Make sure this is a valid field.
(grep $_ eq $column, @db_cols) or return "error building select field: no fields specified!";
$name = $name || $column;
my $query = qq!
SELECT DISTINCT $column FROM $db_table
!;
my $sth = $DBH->prepare ($query) or &cgierr("Unable to query database. Reason: $DBI::errstr. Query: $query");
$sth->execute or &cgierr("Unable to query database. Reason: $DBI::errstr. Query: $query");
# Make a select list out of those names.
$output = qq|<SELECT NAME="$name"><OPTION>---|;
while (($field) = $sth->fetchrow_array) {
($value =~ /^\s*$field\s*/) ?
($output .= "<OPTION SELECTED>$field\n") :
($output .= "<OPTION>$field\n");
}
$output .= "</select>";
$sth->finish;
return $output;
}
Maybe that will help you!
Lynette
Hollister, Ca