Order by rand()
View Single Post
06-10-2008, 06:24 PM
La Vida es Sueño
Join Date: Sep 2007
I can only give you the theory of how I did it. This isn't because I don't want to share it, but it has too many dependencies. What I did was the following:
Generate a random number using PHP. Select from the table where the ID is more or equal to;
Add that selected ID to an array and execute the first query;
When we loop again, follow the same process but append IN() to the end with the previously selected IDs;
Keep doing this until we get the amount we require.
As this is selecting an ID, which should be the primary key, it is a much faster select than choosing a random line from the database.
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
View Public Profile
Send a private message to Wildhoney
Visit Wildhoney's homepage!
Find More Posts by Wildhoney