Skip to content
WJunction - Webmaster Forum

[PHP] alternative to ORDER BY RAND() on large tables

Status
Not open for further replies.
Never run ORDER BY statements on large tables (e.g 4M tables).

Heres some code that will work as an alternative in most cases.
PHP:
$resv = mysql_query('SELECT COUNT(*) FROM v3links');
$row = mysql_fetch_row($resv);
$sval = rand(0,$row[0]-15001);
$query=mysql_query("SELECT `id`,`fileid`,`type`, `filename` FROM `v3links` LIMIT ".$sval.",15000");

enjoy.
 

4 comments

Status
Not open for further replies.

About the author

S
Active Member · Joined
2,474
Messages
240
Reactions
63
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom