By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,948 Members | 1,958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,948 IT Pros & Developers. It's quick & easy.

problem with DBI.pm and ORDER BY RAND() in mysql

P: n/a
When I execute the following SQL statement at the mysql> prompt, I get a
random result:

SELECT proxy FROM proxies WHERE active = 1 ORDER BY RAND() LIMIT 1;

When I wrap it in my perl code, I always get the first row in the database.

my $dbh = DBI->connect("dbi:mysql:$db:host=$db_host", $db_user, $db_pass);

my $sql = "SELECT proxy FROM proxies WHERE active = 1 ORDER BY RAND() LIMIT
1";
my $sth = $dbh->prepare($sql) or die $dbh->errstr;
$sth->execute() or die $dbh->errstr;
while (my $row = $sth->fetch())
{
$proxy = $row->[0];
}

Motiv8x
Top25Web.com: Ranking Report & Search Engine Forums
http://www.top25web.com
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
dw
"Joe Blower" <mo***************@top25web.com> wrote in message
news:am********************@comcast.com...
When I execute the following SQL statement at the mysql> prompt, I get a
random result:

SELECT proxy FROM proxies WHERE active = 1 ORDER BY RAND() LIMIT 1;

When I wrap it in my perl code, I always get the first row in the database.
my $dbh = DBI->connect("dbi:mysql:$db:host=$db_host", $db_user, $db_pass);

my $sql = "SELECT proxy FROM proxies WHERE active = 1 ORDER BY RAND() LIMIT 1";


How about removing the 'LIMIT 1"?
Jul 19 '05 #2

P: n/a
dw
"Joe Blower" <mo***************@top25web.com> wrote in message
news:am********************@comcast.com...
When I execute the following SQL statement at the mysql> prompt, I get a
random result:

SELECT proxy FROM proxies WHERE active = 1 ORDER BY RAND() LIMIT 1;

When I wrap it in my perl code, I always get the first row in the database.
my $dbh = DBI->connect("dbi:mysql:$db:host=$db_host", $db_user, $db_pass);

my $sql = "SELECT proxy FROM proxies WHERE active = 1 ORDER BY RAND() LIMIT 1";


How about removing the 'LIMIT 1"?
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.