Pseudo code:
$min = SELECT MIN(id) from fortunes;
$max = SELECT MAX(id) from fortunes;
While (!$row && $count < 3) {
$id = rand $max + $min;
if ($id > $max) {
next;
}
$row = SELECT * from fortunes where id = $id;
$count++
}
If ($count >= 3) {
return 1st row;
}
--
[snip]
> The way to
> enhance this is by selecting an indexed value, such as the following
> where `foo` is indexed
>
> SELECT `foo` FROM fortunes ORDER BY RAND() LIMIT 1
Why does this help? From the MySQL book I have, the reason ORDER BY
RAND() is slow is because "for each record in the table a
> How many rows do you anticipate that the table will have? Have you
> tested this on your server? I would have to bet that if you
> have only a few K rows that speed/performance will not be an issue.
I doubt I will have more than 100. Perhaps I shouldn't worry about it,
then.
> The way to
> en
[snip]
I understand that I can get a random row out of a table by doing
something
like
SELECT * FROM fortunes ORDER BY RAND() LIMIT 1
But I have also been told that this is a very slow operation.
I am building a script that will display a random saying, user
testimonial,
whatever, on a web pag