PEAR/DB: Random row from result set
| From: | Sebastian Bergmann | Date: | Tue, 24 Apr 2001 15:48:37 +0000 |
| Subject: | PEAR/DB: Random row from result set | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-87@lists.php.net to get a copy of this message | ||
Hi there,
I'm currently wondering if there's a more elegant way to do the
following:
$rows = $db_result->numRows();
switch ($rows) {
case 0: {
die("...");
}
break;
case 1: {
$row = $db_result->fetchRow();
}
break;
default: {
mt_srand((double) microtime() * 1000000);
$random_index = mt_rand(1, $rows);
for ($i = 0; $i < $random_index; $i++) {
$row = $db_result->fetchRow();
}
}
break;
}
I just need a random row from a result set :-/
Thanks,
Sebastian
--
sebastian bergmann sb@sebastian-bergmann.de
http://www.sebastian-bergmann.de
bonn.phpug.de | www.php.net | www.phpOpenTracker.de | www.titanchat.de