Re: Random Numbers..
| From: | Luke | Date: | Mon, 08 Dec 2003 00:58:06 +0000 |
| Subject: | Re: Random Numbers.. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-172137@lists.php.net to get a copy of this message | ||
select all and
use
mysql_data_seek($result, rand(mysql_num_rows($result) - 1));
$row = mysql_fetch_assoc($result);
and there, your random row is returnd, that should be easy enough :) and it
should work
--
Luke
"Theheadsage" <theheadsage@manga-sketchbook.org> wrote in message
news:000401c3bc73$bb1e6c60$15d310ac@yggdrasil...
> Hey,
>
> I've got a script which used to generate a random quote. It worked fine
> untill this problem occurred..
>
> Say we have 4 quotes with QuoteID's of 1 through to 4
> The script would grab a number of rows, and generate a random number
> between 1 and this value (being 4 in this case) This worked fine untill,
> one of the quotes was removed and another added, leaving 4 quotes once
> again, but the last one had an ID of 5. The problem is the Random number
> generated is between 1 and 4, so the final quote is never shown..
>
> I tried using the RAND() function in the MySQL statement it's self, but
> it's not random enough...
>
> Then I thought of doing this:
>
> Select all the Quote ID's from the DB.
> Store them in an Array.
> Generate a random number between 1 and the last ID.
> If the Random Number matches a Quote ID, then display the quote,
> otherwise Generate another
>
> But I couldn't get the code to work. Any suggestions on either how to
> write the above, or made the MySQL RAND() function, more random?