Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Re: [kevinws] PLEASE, SELECT FIELD LIST SHOWing NON REPEATED DATA HOW?

Quote Reply
Re: [kevinws] PLEASE, SELECT FIELD LIST SHOWing NON REPEATED DATA HOW? In reply to
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
Subject Author Views Date
Thread PLEASE, SELECT FIELD LIST SHOWing NON REPEATED DATA HOW? kevinws 4204 Feb 19, 2004, 1:15 PM
Thread Re: [kevinws] PLEASE, SELECT FIELD LIST SHOWing NON REPEATED DATA HOW?
ltillner 4080 Feb 19, 2004, 3:42 PM
Thread Re: [ltillner] PLEASE, SELECT FIELD LIST SHOWing NON REPEATED DATA HOW?
kevinws 4064 Feb 20, 2004, 6:56 AM
Thread Re: [kevinws] PLEASE, SELECT FIELD LIST SHOWing NON REPEATED DATA HOW?
604 4047 Feb 20, 2004, 9:52 AM
Thread Re: [TheStone] PLEASE, SELECT FIELD LIST SHOWing NON REPEATED DATA HOW?
kevinws 4039 Feb 20, 2004, 10:24 AM
Thread Re: [kevinws] PLEASE, SELECT FIELD LIST SHOWing NON REPEATED DATA HOW?
kevinws 4062 Feb 20, 2004, 10:57 AM
Thread Re: [kevinws] PLEASE, SELECT FIELD LIST SHOWing NON REPEATED DATA HOW?
kevinws 4057 Feb 20, 2004, 11:03 AM
Thread Re: [kevinws] PLEASE, SELECT FIELD LIST SHOWing NON REPEATED DATA HOW?
604 4079 Feb 20, 2004, 4:26 PM
Post Re: [TheStone] PLEASE, SELECT FIELD LIST SHOWing NON REPEATED DATA HOW?
qango 4009 Feb 26, 2004, 7:06 AM