Steve Tyler wrote:

> Hi All,
> 
> I've been having a tough time coming up with a good way to do this:
> 
> - I have a (postgresql) DB table containing quoteId, quote, author
> - I want to have a randomly selected quote appear on a web page
> 
> Can anyone suggest an efficient way to do this without having to pull in
> a bunch on data?


How about:

   my $ids = $dbh->selectcol_arrayref("
       SELECT quoteID
         FROM quotes
   ");
   my $random_id = $$ids[ rand(@$ids) ];
   print $dbh->selectrow_array("
     SELECT quote
       FROM quotes
      WHERE quoteID = $random_id
   ");

Ilya, does this belong in a FAQ?

-- 
Jeff

Reply via email to