in reply to Re: popup_menu from database
in thread popup_menu from database

This question comes from the good advise of dws...

How do I fetch a set of rows from MySQL and turn them into a Perl hash?

thx,
Richard

Replies are listed 'Best First'.
Re: Re: Re: popup_menu from database
by Enlil (Parson) on Apr 06, 2003 at 06:43 UTC
    Here is a snippet to help you on your way:
    while ( my $ref = $sth->fetchrow_hashref() ) { print $q->popup_menu( -name => "some_random_name", -values => [keys %$ref], -labels => $ref, -default => 'default_key_from_ref', ); print $q->br; }

    -enlil

      thank you to everyone, I got it to work. Here is how I did it...
      %cat_options = Admin_Get_Cat_options_hash(); # Here is Admin_Get_Cat_options_hash code: sub Admin_Get_Cat_options_hash { my %options_list; $sth = $dbh->prepare (qq{ SELECT id,c_name FROM categories }); $sth->execute(); while (my ($id,$c_name) = $sth->fetchrow_array()) { $options_list{$id} = $c_name; } $sth->finish(); return(%options_list); }
      That worked.
      Thanks for the idea to have it in a sub, dws

      thx,
      Richard