RE: [PHP] Need to display results randomly on mysql 3.22!
| From: | Maxim Maletsky | Date: | Thu, 14 Dec 2000 06:23:22 +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-30258@lists.php.net to get a copy of this message | ||
<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;
}
$v_mysql->query($query); # This is my class MySQL database.
# $noRandom is in case I don't want to use random thing.
# It would be specified somewhere above.
# Also if id was selected then it won't proceed
# $array_ra is being brought by sessions in case you select/selected
an ID,
# we don't want to rotate them all the time, do we...
#it is just for the first-time visit.
if((!$id || !isset($array_ra)) && !$noRandom)
{
$array_ra = array();
$array_ra = rand_num_array($v_mysql->Num);
}
#$v_mysql->Num #the same as (*)
while( list($rand_key, $rand_val) = each($array_ra)) {
and here gfoes your loop ....
...
}
</snip>
I hope this is a good start for to implement RAND() on mySQL 3.22 ...
Cheers,
--maxim
-----Original Message-----
From: Sandeep Hundal [mailto:sandeep_wde@yahoo.com]
Sent: Thursday, December 14, 2000 3:13 PM
To: Maxim Maletsky
Subject: RE: [PHP] Need to display results randomly on mysql 3.22!
Oh Cool! How do you mean thats what you sent me Maxim? Can you let me
peek at some code for that? ;)
Thanks
Sunny
--- Maxim Maletsky <maxim.maletsky@japaninc.net> wrote: > yup, that's
what I sent you .
> I got it running on www.J-Door.com/experts.html
> (just click any area and go wild refreshing it unless you select an
> item)
>
> -maxim
>
> -----Original Message-----
> From: Sandeep Hundal [mailto:sandeep_wde@yahoo.com]
> Sent: Thursday, December 14, 2000 3:01 PM
> To: Daniel Convissor; PHP List
> Subject: Re: [PHP] Need to display results randomly on mysql 3.22!
>
>
> Hi Dan,
>
> sorry for not being more specific. I would like to get the 20
> results
> (based on the WHERE statements) displayed in a random order every
> time.
>
> Sunny
>
> --- Daniel Convissor <danielc@analysisandsolutions.com> wrote: >
> 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
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Shopping - Thousands of Stores. Millions of Products.
> http://shopping.yahoo.com/
>
> --
> 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
>
> --
> 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
>
__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/