Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Global select?

Quote Reply
Global select?
Hi! I am using the following code (thanks to whoever wrote it!) in many places on my site:

Code:
sub {
my $tags = shift;
my $table = $DB->table('HFSHC_members');
my $sth = $table->select (['Username']);
my $output = '<select name=billTO><option value="">--</option>';
while (my $row = $sth->fetchrow_hashref) {
$output .= '<option value='.$row->{Username}.'>'.$row->{Username}.'</option>';
}
$output .= '</select>';
return $output;
}



However, as it is it pulls EVERY Username. What I need is for it to pull just the usernames with Status = Registered. Any ideas? Thanks!
Quote Reply
Re: [ArtistikDD] Global select? In reply to
This should do the trick -

sub {
my $tags = shift;
my $table = $DB->table('HFSHC_members');
my $sth = $table->select({'Status' => 'Registered' }, ['Username']);
my $output = '<select name=billTO><option value="">--</option>';
while (my $row = $sth->fetchrow_hashref) {
$output .= '<option value='.$row->{Username}.'>'.$row->{Username}.'</option>';
}
$output .= '</select>';
return $output;
}

Take a look at the DBManSQL Help pages in your Admin.
GT Module Documentation - Table - "select"
You can build more complex select statements using "select_options".

Hope that helps.
Simon.
Quote Reply
Re: [jai] Global select? In reply to
Thank you very much! That did the trick, and using the Help area you suggested, I was able to figure out how to sort them! Thanks!