
skirrow
stranger
Apr 7, 2002, 3:57 PM
Post #1 of 2
(6930 views)
|
Hi, I want to randomly select a record from a table and display it, how do I do this? The fields in the table are, Comment and Name. At present, I'm using this code but obviously it will display all the records, not just one randomly selected record. my $sth = $dbh->prepare(<<End_SQL) or die "Couldn't prepare statement: $DBI::errstr; stopped"; SELECT Comment, Name FROM `testimonials` End_SQL $sth->execute() or die "Couldn't execute statement: $DBI::errstr; stopped"; while ( my ($comment, $name) = $sth->fetchrow_array() ) { print "<tr><td><font face="Verdana,Arial,Helvetica" size="1"><i>\"$comment\"</i></font></td></tr>\n"; print "<tr><td align=right><font face="Verdana,Arial,Helvetica" size="1"><b>$name</b></font></td></tr>\n"; } All assistance is appreciated. - Neil -- http://www.locked-area.com/ http://www.opencrypt.com/
|