Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Multiselect Problem.

Quote Reply
Multiselect Problem.
I am doing a subroutine to get All Titles (CAT_TITLE, varchar 255, Text Box) from the table (categories) and matches them with another column RELATED for a particular ID to get them selected within a Multiselect box.

But it's not working, any help as what I am doing wrong?

sub {

my $ID = shift;

# connect Table categories
my $table = $DB->table(

# Create a conditional statement for mySQL query
my $cond = GT::SQL::Condition->new(
'CAT_ID', '=', $ID

# Statment handle to get ALL Category Titles
my $sth = $table->select ([

# statment handle to ping RELATED column for CAT_ID (see we are using $cond here).
my $sth2 = $table->select ([
'RELATED'], $cond);

# @present now reprsents elements in the RELATED for particular CAT_ID.
my @present;
@present = $sth2->fetchrow_array;
# For Testing Purpose
print @present;

# Now call $sth and print all CAT_TITLE and if matches with @present turn them 'Selected'
my $output =
'<select name=RELATED multiple>';

while (my $row = $sth->fetchrow_hashref)

if ( grep {$_ eq $row->{CAT_TITLE}} @present) {
$output .=
'<option value="'.$row->{CAT_TITLE}.'" SELECTED>'.$row->{CAT_TITLE}.'</option>';
else {
$output .=
'<option value="'.$row->{CAT_TITLE}.'">'.$row->{CAT_TITLE}.'</option>';
$output .=

return $output;

Thanks in advance.
Subject Author Views Date
Post Multiselect Problem. Sara_Samsara 1796 Sep 10, 2005, 12:31 AM