in reply to Re: CGI.pm - scrolling_list and %labels hash
in thread CGI.pm - scrolling_list and %labels hash
What I've got is a hash where they key is a record number and the value is text. I want to pass the keys as -values, but sorted by the hash values. Here's my code... no laughing please....
I know the $restaurants{$row->[5]}=$row->[0] . " " . $row->[1] . " \/ " . $row->[3]; is a little convoluted, but I wanted to end up with:my %restaurants=&queryrestaurants; my @restaurantvalues=keys(%restaurants); print start_multipart_form(); print center(scrolling_list(-name=>'restauranttitle',-values=> +[@restaurantvalues],-default=>undef,size=>14,-multiple=>'false',-labe +ls=>\%restaurants),submit(-name=>'job',-value=>'edit'),submit(-name=> +'job',-value=>'new')); print endform; sub queryrestaurants { my (%restaurants,$restaurant,$address1,$address2,$zipcode,$phonenu +mber,$record); use DBI; my $dbh = DBI->connect("DBI:mysql:dbname:$sqlserver:3306","log +in","passwd"); my $sql_statement = "SELECT \* FROM location order by restaura +nt"; my $sth = $dbh->prepare($sql_statement); $sth->execute() or die "Can't execute SQL statement : $dbh->er +rstr"; $sth->bind_columns(undef, \$restaurant,\$address1,\$address2,\ +$zipcode,\$phonenumber,\$record); my $row; while ($row = $sth->fetchrow_arrayref) { $restaurants{$row->[5]}=$row->[0] . " " . $row->[1] . " \/ + " . $row->[3]; } $sth->finish; $dbh->disconnect; return %restaurants; }
<option value="42">Some Restaurant 200 Main St / 04444</option>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: CGI.pm - scrolling_list and %labels hash
by Kanji (Parson) on Feb 15, 2002 at 04:28 UTC | |
by naChoZ (Curate) on Feb 15, 2002 at 05:05 UTC |