我试图从数据库中获取值并将它们放在HTML <select>标记内的下拉列表中。
我能够在一个长字符串中获取值并在一个选项中显示所有值,但我想将每个值放在一个单独的<option>标记中。 我只是不知道我可以使用什么逻辑来做到这一点。
这是我到目前为止所拥有的:
#!c:\perl\bin\perl.exe use CGI; require ("data_eXchangeSubs.pm"); $query = new CGI; print $query->header(-expires=>'-1d'); print $query->start_html( -title=>'Dex Vendor Testing', -bgcolor=>'white' ); $user = $query->param("user"); my $dataX = ${ConnectToDatabase($main::DBone, $main::dataENV)}; $resultSet = $dataX->Execute("select vendor from dex_vendor_info group by vendor"); while(!$resultSet->EOF) { $vendors .= $resultSet->Fields("vendor")->Value."\n"; $resultSet->MoveNext; } print <<ONE; <table width=75% border=0> <th colspan=2 align=left><strong><font size=5pt color=#FF6633 face=garamond>Vendor Information</strong</font><hr size=4pt color=midnightblue></th> <tr> <td align=left nowrap><font size=4pt face=garamond><label id=lVendor for=vendor><strong>Company Name</strong></font></label></td> <td align=left nowrap><font size=4pt face=garamond><label id=lVendor for=vendor><strong>Contact's Name</strong></font></label></td> </tr> <tr> <td align=left nowrap><select id="vendors"> <option>$vendors</option> </td> </td> <td align=left nowrap><input type=text name="contact" id=contact value="" size=25></td> </tr> </table> <br> ONE print $vendors; print $query->end_html;I am trying to get values from a database and place them in a dropdown list within an HTML <select> tag.
I'm able to get the values in a long string and display all of them within a single option but I want to put each value in a separate <option> tag. I just don't know what logic I could use to do this.
Here's what I have so far:
#!c:\perl\bin\perl.exe use CGI; require ("data_eXchangeSubs.pm"); $query = new CGI; print $query->header(-expires=>'-1d'); print $query->start_html( -title=>'Dex Vendor Testing', -bgcolor=>'white' ); $user = $query->param("user"); my $dataX = ${ConnectToDatabase($main::DBone, $main::dataENV)}; $resultSet = $dataX->Execute("select vendor from dex_vendor_info group by vendor"); while(!$resultSet->EOF) { $vendors .= $resultSet->Fields("vendor")->Value."\n"; $resultSet->MoveNext; } print <<ONE; <table width=75% border=0> <th colspan=2 align=left><strong><font size=5pt color=#FF6633 face=garamond>Vendor Information</strong</font><hr size=4pt color=midnightblue></th> <tr> <td align=left nowrap><font size=4pt face=garamond><label id=lVendor for=vendor><strong>Company Name</strong></font></label></td> <td align=left nowrap><font size=4pt face=garamond><label id=lVendor for=vendor><strong>Contact's Name</strong></font></label></td> </tr> <tr> <td align=left nowrap><select id="vendors"> <option>$vendors</option> </td> </td> <td align=left nowrap><input type=text name="contact" id=contact value="" size=25></td> </tr> </table> <br> ONE print $vendors; print $query->end_html;最满意答案
如果您正在使用CGI,请使用CGI。
print $query->popup_menu( -name => 'vendors' , -values => \@list_of_vendors , -default => $default_vendor );你在行处理循环中得到@list_of_vendors :
my @list_of_vendors; while(!$resultSet->EOF) { push @list_of_vendors, $resultSet->Fields("vendor")->Value; $resultSet->MoveNext; }如果您希望标签与值包含-labels标签中的值不同, -labels其指向包含您想要的文本的数组引用。
If you're using CGI, then use CGI.
print $query->popup_menu( -name => 'vendors' , -values => \@list_of_vendors , -default => $default_vendor );And you get @list_of_vendors in your row processing loop:
my @list_of_vendors; while(!$resultSet->EOF) { push @list_of_vendors, $resultSet->Fields("vendor")->Value; $resultSet->MoveNext; }If you want labels to be a different text value from values include -labels tag in the call and point it to an array ref containing the text you want visible.
更多推荐
发布评论