PDA

View Full Version : Random results from Mysql


Yahook
06-11-2005, 11:25 PM
There are two different ways to do it:

1) Using the query like this one:
$sql = "SELECT * FROM tablename
LIMIT $num1,$NUM_RESULTS";
where $num1 - random number from php script

2) Using the query like this one:
$sql = "SELECT * FROM tablename
ORDER BY RAND() LIMIT $NUM_RESULTS";

xariton
06-12-2005, 07:16 AM
Thanks Yahook ;)
If you have a large database it's better to use first method.
"ORDER BY RAND()" - is not good to use with large database

Yahook
06-12-2005, 09:39 AM
Thanks Yahook
If you have a large database it's better to use first method.
"ORDER BY RAND()" - is not good to use with large database

I agree with you but it's working only for one result. If you want to select more than one result you should make several queries to database - that's also not good.