Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Sort select field

Quote Reply
Sort select field
Hi, I´m using this global sub to generate the select forms

- create_select:
sub {
my $col = shift;
my $tags = GT::Template->tags;
my $cols = $tags->{home}->{db}->cols;
return if (lc $cols->{$col}->{'form_type'} ne 'select');
my $values;
my $selected = $tags->{values}->{$col};
my $form_values = $cols->{$col}->{'form_values'};
my $form_names = $cols->{$col}->{'form_names'};
if ($form_values and $form_names and ($#$form_values == $#$form_names)) {
for my $i (0..$#$form_values) {
exists $values->{@$form_values[$i]} or $values->{@$form_values
[$i]} = @$form_names[$i];
}
}
else {
$values = $cols->{$col}->{values};
}
return $tags->{home}->{disp}->select ( {
name => $col,
values => $values,
value => $selected,
blank => 1,
});
}

But I want to sort the numbers

If it´s less than 10, it be ok 0,1,2,3,4,5,6,7,8,9

But if it´s more than 10 it get´s too confused like 37,38,39,20,21,22,23,40,24,41 (this sequence)

What can I do to sort 11,12,13,14 ... ?

Thanks

Fábio
Quote Reply
Re: [assombracao] Sort select field In reply to
Are the numbers the option names or values or.. ?

Last edited by:

Paul: Apr 3, 2002, 8:43 AM
Quote Reply
Re: [Paul] Sort select field In reply to
the numbers are the options and values

the name is like floor

From:

Apartment floor <%floor%>
Quote Reply
Re: [assombracao] Sort select field In reply to
It looks like the value of $cols->{$col}->{'form_values'} is an array reference?

Is that right?

If so try:

my $form_values = sort @{$cols->{$col}->{'form_values'}};

I have to admit I don't get this bit:

($#$form_values == $#$form_names)

How can a number equal a word?

Last edited by:

Paul: Apr 3, 2002, 8:57 AM
Quote Reply
Re: [Paul] Sort select field In reply to
Thank´! it seens to be working great

I´m not a perl programmer

but I think it calls the form names and values from the names that I have putted in the Table Definition



andares_predio ENUM(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50) No andares do prédio SELECT



Not really sure but it´s working great now

Thanks

Fábio
Quote Reply
Re: [assombracao] Sort select field In reply to
Ah ok I see.

Glad it worked.