RE: RE: [PHP] Random not working?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You might try getting the random number before the query.

-----Original Message-----
From: Rich Gray [mailto:rich@f1central.net]
Sent: Saturday, March 01, 2003 8:37 PM
To: Frank Keessen; php-general@lists.php.net; php-db@lists.php.net
Subject:  RE: [PHP] Random not working?


> Hi All,
>
> I'm trying to get a random record each time this script runs;
> Only it's giving me everytime the first record back.. No random at all..
>
> // generate and execute query
> $query = "SELECT stedenid, naamstad, stadomschrijvk FROM steden
> ORDER BY RAND() LIMIT 1";
> $result = mysql_query($query) or die ("Error in query: $query. "
> . mysql_error());
> $row = mysql_fetch_object($result);
> echo $row->naamstad;
>
>
> Version info;
>
> PHP 4.3.1
> Mysql 3.23.54
>
> When i'm trying to excute the SELECT statement in phpmyadmin; i'm
> only getting the first record back and when i'm taking off the
> LIMIT 1 it will display all the records in ascending order so
> also not in random..
>
>
> Regards,
>
> Frank


Frank

This really belongs on the MySQL list but there was a known issue with
RAND() on 3.23.54 - can you upgrade? If your table has an auto_increment ID
column then a workaround would be to use rand() in PHP to generate a random
ID then use that with a 'where id = '.$id in your query...

HTH
Rich


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux