RE: [PHP] Need to display results randomly on mysql 3.22!
| From: | Maxim Maletsky | Date: | Thu, 14 Dec 2000 05:57:04 +0000 |
| Subject: | RE: [PHP] Need to display results randomly on mysql 3.22! | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-30255@lists.php.net to get a copy of this message | ||
Here's the functiopn I once wrote exactly for this purpose:
<snip>
function rand_num_array($count)
{
$stand_a = array();
$rand_a = array();
for( $i = 0; $i < $count; $i++ )
$stand_a[$i] = $i;
$rand_max = $count;
for( $i = 0; $i < $count; $i++ )
{
$rand_index = rand(0, $rand_max);
if( $rand_index == $rand_max )
$rand_index = $rand_max - 1;
$rand_a[$i] = $stand_a[$rand_index];
for( $j = $rand_index; $j < $rand_max - 1; $j++ )
$stand_a[$j] = $stand_a[$j + 1];
$rand_max--;
}
return $rand_a;
}
</snip>
// It works with my mysql class of PHPLIB.
you first say how many numbers you need over there and then it will give
them to you in a random order.
hope this helps.
Cheers,
Maxim Maletsky.
-----Original Message-----
From: Daniel Convissor [mailto:danielc@analysisandsolutions.com]
Sent: Thursday, December 14, 2000 2:42 PM
To: PHP List
Subject: Re: [PHP] Need to display results randomly on mysql 3.22!
Howdy Sandeep:
So, do you want to get a random 20 lines from the database? Or do you want
the 20 items to be displayed randomly?
--Dan
--
PHP scripts that make your job easier
http://www.analysisandsolutions.com/code/
SQL Solution | Layout Solution | Form Solution
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
4015 7 Ave, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
--
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