List:General Discussion« Previous MessageNext Message »
From:Matt W Date:November 4 2003 11:41pm
Subject:Re: RAND ()
View as plain text  
Hi Payne,

This is probably because of a bug in MySQL versions before 3.23.56 and
4.0.10 -- RAND() didn't work right the first time it was used in a *new*
connection. After the first run, though, it was OK.

To work around the problem, I've told people to just call RAND() a few
times before doing your query. Just like this in PHP:

mysql_query('SELECT RAND(), RAND(), RAND()');

Then the ORDER BY RAND() query should be random. Now that I think about
it, putting RAND() twice in the ORDER BY would probably have the same
effect. So you could try

$result = mysql_query('... ORDER BY RAND(), RAND() LIMIT 1');

Hope that helps.


----- Original Message -----
From: "Payne"
Sent: Tuesday, November 04, 2003 10:33 AM
Subject: RAND ()

> Hi,
> I have been playing around with RAND(). It works very well if I do a
> statement with mysql, but I having problem using with mysql statement
> with php. When a person calls on the page,  the same output is always
> view. How can I get RAND() work with php.
> sorry for the php, stuff. Thanks for any help you can give.
> Payne

RAND ()Payne4 Nov
  • Re: RAND ()Matt W5 Nov