Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting Random Quotes from mySQL :(

Status
Not open for further replies.

perlTest

Programmer
Nov 16, 2002
14
0
0
US
Hello there,

I've a mysql database which I want to select random quotes everytime. But I have no idea how to do that. My table is shown below:

quotes:
pid|text|link

I wanna select randomly each time. I've tried the following, but no luck.

$SQL = "SELECT text from quotes ORDER BY Rand()";

Please Help if you can. Thank You.
 
What is the way you did? Following don't work:

$sql = qq[select TextAd from TextAds ORDER BY RAND()];

my $sth = $dbh->prepare("$sql");
$sth->execute or &head(&quot;Cannot execute statement!<br>&quot;.$sth->errstr);
while(@row = $sth->fetchrow) {
$random = $row[0];
}

print $random;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top