Good day. Please help me figure it out. Below is a piece of code that I want to get from the table the value of one column, in this case $ PG1 ... $ PG10 should have the value 600 ... 610, respectively. But when printing, they are duplicated several times, that is, it is displayed:
600 601 ... 610 600 601 ... 610 How to get each value only once and assign it to a variable?
my $dbqueryPRODGRP = $db->prepare("select f1 from DPTDAT group by f1"); $dbqueryPRODGRP->execute(); my @rowPRODGRPs; while (my ($rowPRODGRP)=$dbqueryPRODGRP->fetchrow_array()) { push @rowPRODGRPs, $rowPRODGRP; foreach $rowPRODGRP(@rowPRODGRPs) { my ( $PG1,$PG2,$PG3,$PG4,$PG5,$PG6,$PG7,$PG8,$PG9,$PG10,)=@rowPRODGRPs; print $PG1."\n", $PG2."\n",$PG3."\n",$PG4."\n",$PG5."\n",$PG6."\n",$PG7."\n",$PG8."\n",$PG9."\n",$PG10."\n"; } } The corrected version that worked.
my $dbqueryPRODGRP = $db->prepare("select f1 from DPTDAT group by f1 order by f1"); $dbqueryPRODGRP->execute(); my @rowPRODGRPs;#Задаем имя массиву while (my ($rowPRODGRP)=$dbqueryPRODGRP->fetchrow_array()) { push @rowPRODGRPs, $rowPRODGRP;#Записываем каждый результат в лист массива }
}related towhile) type. Or, without any arrays, type the string as soon as it is received from the database - Mike