Jeff Zucker wrote:
>
> Steve Tyler wrote:
>
>> - I have a (postgresql) DB table containing quoteId, quote, author
>> - I want to have a randomly selected quote appear on a web page
>
> How about:
>
> my $ids = $dbh->selectcol_arrayref("
[snip]
Or, given the fact that PG can return the number of rows without
explicitly fetching and that it has a limit clause, this would work with
fewer explicit fetches than my previous example, but wouldn't be as
portable:
my $sth=$dbh->prepare("SELECT quoteID FROM quotes");
$sth->execute;
my $rows = $sth->rows;
$sth->finish;
my $random_id = int rand($rows) ;
print $dbh->selectrow_array("
SELECT quote FROM quotes LIMIT 1, $random_id
");
--
Jeff