嗨,我试图从中选择一个随机数:
我的来源:
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)
{
chomp $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 />";
}
}
我怎样才能只打印一个随机行???我尝试过这样的事情:
my $sth = $dbh->prepare("SELECT nazov_receptu FROM recepty WHERE nazov_receptu LIKE '%$line%' AND kategoria == 'p' AND (rowid = (abs(random()) % (select max(rowid)+1 from recepty)) or rowid = (select max(rowid) from recepty)) order by rowid limit 1;");
但不清楚...我不知道为什么...
我正在使用 SQLite 并将其打印到 Web 界面。
有 input.txt 的时候可以试试:
A
C
数据库:
id name
1 A
2 B
3 C
4 D
5 E
出去:
A OR C (random)