Re: PEAR/DB: Random row from result set
| From: | Frank M. Kromann | Date: | Tue, 24 Apr 2001 16:31:54 +0000 |
| Subject: | Re: PEAR/DB: Random row from result set | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-89@lists.php.net to get a copy of this message | ||
fbsql and mssql should allow this too.
- Frank
> 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 *
>
> --
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, e-mail: pear-general-unsubscribe@lists.php.net
> For additional commands, e-mail: pear-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>
>