Re: PEAR/DB: Random row from result set

From: Date: Tue, 24 Apr 2001 15:51:46 +0000
Subject: Re: PEAR/DB: Random row from result set
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-88@lists.php.net to get a copy of this message
On Tue, 24 Apr 2001, Sebastian Bergmann wrote: > 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 :-/ MySQL supports seeking within the result set. Do other backends allow for this? -Andrei * "UNIX, isn't that some archaic form of DOS?" - our job applicant *

« previous php.pear.general (#88) next »