Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: creating CGI::scrolling_list ... can this be shortened?

by geektron (Curate)
on Jul 25, 2005 at 16:52 UTC ( [id://477896]=note: print w/replies, xml ) Need Help??


in reply to Re^3: creating CGI::scrolling_list ... can this be shortened?
in thread creating CGI::scrolling_list ... can this be shortened?

What I don't understand is why you are using a hash for this, it's not necessary, you can use the result array, it gives you the right order... taking the result and then copying it to a hash is not necessary.

well, in order to have the labels for the scrolling_llist different than the values, per the CGI documentation, an array of values and a hash of value -> label mappings *is* needed.

i'm creating:

<select> <option value='1'>Foo </option> <option value='3'>Baz </option> </select>
now i realize that hashes are nothing more than special arrays, *but* in order to create the sample above, CGI::scrolling_list requires an array of values *and* the (optional) hash of label mappings.

i haven't tried to let perl massage the resulting array into a hash, *but* it's also an arrayref of hashrefs (as i've written the fetch), and CGI::scrolling_list doesn't understand that.

Replies are listed 'Best First'.
Re^5: creating CGI::scrolling_list ... can this be shortened?
by fmerges (Chaplain) on Jul 26, 2005 at 14:20 UTC

    Hi,

    Try this:

    #... use strict; use DBI; use CGI; #... my $statement = "SELECT id, display_name FROM membership ORDER BY disp +lay_name"; my $result = $dbh->selectall_arrayref($statement); my %h = map { $_->[0] => $_->[1] } @$result; my $cgi = new CGI; print $cgi->scrolling_list( -name => 'list_name', -multiple => 'true', -values => [ sort keys %h ], -labels=> \%h, ); #...

    Read the man page of DBI, there is explain how the combination of -values and -labels work.

    And don't forget to check the result of the statement.

    Regards,

    |fire| at irc.freenode.net

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://477896]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2024-04-23 08:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found