Hello, Fellow monks...
I've tried looking for the answer to this in the Super search, by searching for the above title, but could not find the correct way to do this...
I've asked on a MySQL list, but have not recieved any type of reply. I know this is mostly a MySQL question, but it also has to do with Perl, since it's Perl and CGI.pm handling this. So if you know how I can do this, can you please point me in the right direction.
I have a database with Categories, which I could just do this:
while (my $something = $sth->fetchrow_hashref()) {
$option_list .= qq~<option value="~ . $something->{id} . qq~">~ .
+ $something->{cat_name} . qq~</option>\n~;
}
Then
$option_list would have my option list. However, I am going to use it for anywhere from 10 to 100 different forms on each page, depending on the setting, and each one will have a different default, so how can I put it in a hash or array, where I can use CGI.pm's popup_menu?
Here is what I want to be able to do, something like this:
popup_menu(-name=>"somename1",
-values=>[%options],
-labels=>[\%options],
-default=>$somename1_value);
Something like that. Of course, it would be customized to my scripting style, but that is way I'm trying to pull the data out of the database.
here is what I have thus far:
$sth1 = $dbh->prepare (qq{ SELECT * FROM categories });
$sth1->execute();
%cat_options = ();
while (my $oc111 = $sth1->fetchrow_hashref()) {
$cat_options{$oc111->{id}} = $oc111->{c_name};
}
$sth1->finish();
# And for the popup_menu:
popup_menu(-name=>"cid",
-values=> [%cat_options],
-labels=>{\%cat_options},
-default=>$row->{cid},
-class=>"formfield_left")
That does not work. ;(
I'd really appreciate any advice.
thx,
Richard
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.