Re: Random Record Retrieval
| From: | Martin Geisler | Date: | Sun, 23 May 2004 09:53:41 +0000 |
| Subject: | Re: Random Record Retrieval | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-186788@lists.php.net to get a copy of this message | ||
rkerr@digitaliguana.com (Robb Kerr) writes:
> How's that for alliteration in a subject line?
Very nice! :-)
> [...] And, if this is the best way to go, unfortunately I don't
> know how to write a random number generator in PHP so would
> appreciate any help.
Your idea sounds good, and luckily you don't have to build your own
random generator, behold:
http://php.net/rand
Then call rand() with two arguments: the minimum and maximum ID, and
it will give you a random integer back between those two numbers.
You could also opt to have MySQL make the random number for you, and
then do a query like
SELECT * FROM table ORDER BY RAND() LIMIT 1;
Then you wont have to deal with figuring out the number of rows in the
table as you would in the PHP case. You can also increse the limit
to, say, 3 and then show three random quotes on your pages. See
http://dev.mysql.com/doc/mysql/en/Mathematical_functions.html#IDX1363
for a description of RAND() in MySQL.
--
Martin Geisler My GnuPG Key: 0xF7F6B57B
PHP EXIF Library | PhpWeather | PhpShell
http://pel.sf.net/ | http://phpweather.net/ | http://gimpster.com/
Read/write EXIF data | Show current weather | A shell in a browser