2007. 02. 20, kedd keltezéssel 01.33-kor Fergus Gibson ezt írta:
> How about this instead, Mike?
> 
> <?php
> // some code
> 
> $fortune = mysql_query("SELECT text FROM fortunes ORDER BY RAND() LIMIT 1");
> $fortune = mysql_fetch_row($fortune);
> $fortune = sprintf(
> '<span class="quotecyc">&quot;%s&quot;<br />-Omniversalism.com</span>',
> $fortune[0]
> );
> 
> // some more code
> ?>
> 
> MySQL is implemented in random code, so it can probably perform this
> operation faster, and this code is much cleaner.  You may want to move
> away from mysql since it's essentially deprecated.  I have switched to
> mysqli and prefer it.
> 

a week ago or something like that there was an extensive discussion here
about ORDER BY RAND being slow and inefficient on large tables

read this:
http://www.titov.net/2005/09/21/do-not-use-order-by-rand-or-how-to-get-random-rows-from-table/

greets
Zoltán Németh

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to