RE: [PHP] random record mysql
| From: | Jack Dempsey | Date: | Fri, 25 Apr 2003 16:22:44 +0000 |
| Subject: | RE: [PHP] random record mysql | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145293@lists.php.net to get a copy of this message | ||
i'm not sure where the difficulty lies...searching mysql.com i found this:
From version 3.23 you can do: SELECT * FROM table_name ORDER BY RAND() This
is useful to get a random sample of a set SELECT * FROM table1,table2 WHERE
a=b AND c<d ORDER BY RAND() LIMIT 1000. Note that a RAND() in a WHERE clause
will be re-evaluated every time the WHERE is executed.
in php, all you'd have to do with a result set is to find the number of
items in the array, then make a random number % that number, and use that as
your index...
hth,
jack
> -----Original Message-----
> From: tbo [mailto:tim@copiousdg.com]
> Sent: Thursday, April 24, 2003 8:44 PM
> To: php-general@lists.php.net
> Subject: [PHP] random record mysql
>
>
> For the life of me I cannot figure out how to get a random record to be
> displayed off a record set using mysql and php. I have seen
> examples of the
> rand() function but it only brings up the first record in the record set.
> Any ideas or tutorials? Please help!!!! :)
>
> --
> Tim Haskins
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>