RES: [PHP] Randomly select 5 records from a db
| From: | Carlos Henrique | Date: | Tue, 03 Oct 2000 13:58:05 +0000 |
| Subject: | RES: [PHP] Randomly select 5 records from a db | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-18418@lists.php.net to get a copy of this message | ||
Hi Ben, I did something similar last week but not using the random numbers
in where clause. My approch was take the random numbers to move pointer
through the results using mysql_data_seek().
Carlos
> -----Mensagem original-----
> De: Ben Weinberger [mailto:ben@digitalsmiths.com]
> Enviada em: segunda-feira, 2 de outubro de 2000 21:33
> Para: Paul DuBois; php-general@lists.php.net
> Assunto: Re: [PHP] Randomly select 5 records from a db
>
>
> Hmm... tried that and still get the same error... odd-- i looked
> and we are
> running 3.22.27, and rand() may not work with our version...
> so-- I've come
> up with a different solution for now... Here's what I have...
>
> <?
> // connect to database here
>
> srand(time());
> while(++$count <= 3) {
> $num[$count] = rand(0, 8);
> $mySQL = "SELECT * FROM meminfo WHERE (type='bene') AND
> (id='$num[$count]')";
> $results = mysql_query($mySQL);
>
> $myrow=mysql_fetch_row($results);
>
> print($myrow[2] . "\n");
> }
>
> mysql_close($db);
> ?>