RE: [PHP] Shuffling a mySQL Result Set
| From: | Ben Gollmer | Date: | Mon, 31 Jul 2000 01:27:51 +0000 |
| Subject: | RE: [PHP] Shuffling a mySQL Result Set | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-9096@lists.php.net to get a copy of this message | ||
The best solution is to let MySQL do the randomization.
If you are running MySQL 3.23.3 or later, you can do
$result = mysql_query("select id from table where id in (1,2,3,4) order by rand()");
On older versions, a bit of sql voodoo is necessary
$result = mysql_query("select id, id*0+rand() as rand_col from table where id in (1,2,3,4) order by rand_col");
Ben Gollmer
Jatosoft, LLC
http://www.jatosoft.com/
________________________________________________________________________
At 05:41 PM 7/30/2000 -0700, you wrote:
Hello,
Say I run the following mysql query:$result = mysql_query ("SELECT id FROM table WHERE id in (1,2,3,4)"); Is it possible to run the shuffle() function on $result e.g. shuffle ($result); Would this shuffle the result set e.g. randomize? Thanks! Andrew digi-FX ------------------------------- http://www.digi-FX.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net