Re: Re: WHERE problem

From: Date: Tue, 20 Feb 2007 09:35:59 +0000
Subject: Re: Re: WHERE problem
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-249070@lists.php.net to get a copy of this message
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

« previous php.general (#249070) next »