Results 1 to 4 of 4
Aug 22, 2011, 20:27 #1
Is there any way to select random record from database with mysqli
I'm a newbie to MySQLi and have searched the internet for almost two weeks but cannot find any best result.
Is there any good way to select random records from database using mysqli better than ORDER BY RAND() function?
I heard this function takes times to process just to pick out five from a million records in the database.
Or else, should I use a traditional MySQL way instead of this.
Thanks in advance
Aug 22, 2011, 22:16 #2
- Join Date
- May 2007
- Poole, UK
- 88 Post(s)
- 0 Thread(s)
Have a read of this thread where different methods are discussed. The method I personally prefer is to run the select query without the use of a limit to get all records that can be chosen from then once the result set is in an array. Then I would use array_rand() on the result set to grab x random rows.
Aug 22, 2011, 22:48 #3
Thanks for pointed out. I read it now.
Aug 23, 2011, 07:10 #4
Hello there again SpacePhoenix,
I've tested your code. It's perfect for me.