Gossamer Forum
Quote Reply
help with a global
 
I have a field in my Link table with the following entered into the form names and form value fields.

City1 - Suburb1
City1 - Suburb2
City1 - Suburb3
City1 - Suburb4
City1 - Suburb5

City2 - Suburb1
City2 - Suburb2
City2 - Suburb3
City2 - Suburb4
City2 - Suburb5

I have added a select meun to the search page which automatically builds a select menu using these values - works fine.

But what I now want to do is split the menu at the "-" so it only includes the first part of each item. Then I'll pass that to the search script so it includes all Suburbs under the chosen City in the search results. That means every menu entry won't be there - it will end up building a menu like...

City1
City2
City3
City4

The new menu, when submitted would be the equavilent of doing a mysql statement with an % on the end like...

Code:
select * from Links where Location like 'City2 -%';

Can anyone show me how to alter the following global to do that?...
Code:
sub {
my $column = shift;
my $selected = shift;
my $table = $DB->table("Links");
my %hash;
my $i = 0;
my $names = $table->form_names->{$column};
my $vals = sort $table->form_values->{$column};
for my $val (@$vals) {
$hash{$val} = $names->[$i++];
}
my $html = $DB->html($table, $IN);
my $form = $html->select({
name => "$column",
values => \%hash,
value => $selected
});
return $form;
}

Thanks

Regan.
Quote Reply
Re: [ryel01] help with a global In reply to
$table = $DB->table('Links');
$sth = $table->select( { Location => 'City- %' } );

Maybe something like this... not sure though...

- Jonathan