我试图从数据库中的表中选择与文件中数组中的行相同的所有列。例如:
TABLE:
id name
1 A
2 B
3 C
FILE:
A
B
我只想选择 A 和 B。
我的来源:
use DBI;
use CGI;
my $file = '.\input.txt'; # Name the file
open(FILE, $file) or die("Unable to open file");
my @data = <FILE>;
foreach my $line (@data)
{
#print $line;
my $sth = $dbh->prepare("SELECT columnA FROM table WHERE columnA LIKE '%$line%'");
$sth->execute;
my $result = $sth->fetchall_arrayref;
foreach my $row ( @$result ) {
print "- ";
print "@$row\n";
print "<BR />";
}
}
但它只写最后一行选择嗯...
OUTPUT I GET
B
OUTPUT I WANT TO GET
A
B
我用这个试过:
INPUT:
bengalske_stehno
cesnakova_polievka
drzkova_polievka
kuraci_spiz
polievka_fazulova
polievka_mrkvova
polievka_rybacia
DATABASE:
fasirky
cesnakova_polievka
chlebicek_biskupsky
drzkova_polievka
polievka_fazulova
polievka_mrkvova
polievka_rybacia
bengalske_stehno
OUTPUT:
- polievka_rybacia