Random ID?

kaits

Mitglied
Hi

How can I get on every page load a random ID from MySQL table when the ID's are like next:

1
2
4
7
32
34
66
657
678
699

ect

ORDER BY RAND() doesn't work :(

I will shoe on every page load one of these ID's but how??

feel free to answer in german ;)
 
mysql.com
RAND()
RAND(N)
Returns a random floating-point value in the range 0 to 1.0. If an integer argument N is specified, it is used as the seed value:


mysql> SELECT RAND();
-> 0.9233482386203
mysql> SELECT RAND(20);
-> 0.15888261251047
mysql> SELECT RAND(20);
-> 0.15888261251047
mysql> SELECT RAND();
-> 0.63553050033332
mysql> SELECT RAND();
-> 0.70100469486881

You can't use a column with RAND() values in an ORDER BY clause, because ORDER BY would evaluate the column multiple times. In MySQL Version 3.23, you can, however, do: SELECT * FROM table_name ORDER BY RAND() This is useful to get a random sample of a set SELECT * FROM table1,table2 WHERE a=b AND c<d ORDER BY RAND() LIMIT 1000. Note that a RAND() in a WHERE clause will be re-evaluated every time the WHERE is executed. RAND() is not meant to be a perfect random generator, but instead a fast way to generate ad hoc random numbers that will be portable between platforms for the same MySQL version.

Eine andere Möglichkeit wäre das Auslesen vorhandener Zeilen in ein php-Array. Dann wird die Array-Random-Funktion verwendet und noch ein query gestartet.
 
Zurück