html - 使用 Perl 从 MySQL 填充下拉列表

标签 html mysql perl

我正在尝试从 mysql 数据填充下拉列表并从 Populating a Drop-Down list using DBI 获得解决方案和 How do I get selected value from drop down box in Perl CGI

我有以下代码:

#!/usr/bin/perl
use warnings;
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use Data::Dumper;
print "Content-type: text/html\n\n";
my $dbh = DBI->connect();
my @tables=$dbh->selectcol_arrayref('select TABLE_NAME from 1009_table_list order by TABLE_NAME');
print Dumper@tables; #this dumper is giving results
print qq[
<!DOCTYPE html>
<html>
<head></head>
<body>
<form id="upload-form"><table>
<tr><td>Table Name:</td><td><select name="tbname">
];
print Dumper@tables; # this dumper is not printing anything
foreach my $table(@tables)
{
print qq "<option value=\"$table\">" . $table . "</option>";
}
print qq[
</select>
</td></tr>
</table></form></body>
</html>
];

在代码中的第二个注释中,我无法获得下拉列表的@tables 的值。 为什么?

最佳答案

selectcol_arrayref 返回数组 ref,所以:

my $tables = $dbh->selectcol_arrayref('select TABLE_NAME from 1009_table_list order by TABLE_NAME');

foreach my $table (@$tables) {
  print qq{<option value="$table">$table</option>};
}

关于html - 使用 Perl 从 MySQL 填充下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18842676/

相关文章:

html - Bootstrap中嵌套文本元素相关的列表高度扩展

最后一个字母为 '%n' 的 mysql SELECT 字符串不起作用

javascript - semantic-ui - Modal 没有风格

html - 固定div的CSS水平居中?

mysql - 从没有自动递增的表中获取最后一个主键

mysql - 在 MySQL 查询中连接表而不是多个查询

perl - 我应该在编译时而不是运行时建立继承,如果是,为什么?

perl - 用 perl 编写 CSV

perl - 在 DBIx::Class 中将 CAST(foo AS type) 作为关系条件传递

javascript - 在 Javascript 中显示/隐藏多个表列