Random selection

This is a discussion on Random selection within the PHP General forums, part of the PHP Programming Forums category; Hi You can use "select distinct names from table_name order by rand() limit 3". Hope this helps and ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-23-2003
Binay Agarwal
 
Posts: n/a
Default Re: [PHP] Random selection

Hi

You can use "select distinct names from table_name order by rand() limit 3".
Hope this helps and let me know.

cheers
Binay


----- Original Message -----
From: <fkeessen@planet.nl>
To: <php-general@lists.php.net>
Sent: Saturday, August 23, 2003 6:36 PM
Subject: [php] Random selection


> Hi,
>
> Can you help me with this one??
>
> In my mysql db i have a colum called names;
>
> In names their are:
>
> Frank
> Frank
> Bob
> Alice
> Bob
> Alice
> Jim
> Alice
> Frank
>
> I want to make a random selection (max 3 value's for example).. Only it

may not produce two times the same name. For example;
>
> This is the output:
>
> Frank, Jim, alice
>
> Wrong output
>
> Frank, Frank, Jim
>
> Please help!
>
> Thanks,
>
> Frank
>
>
>



----------------------------------------------------------------------------
----


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



Reply With Quote
  #2 (permalink)  
Old 08-23-2003
fkeessen@planet.nl
 
Posts: n/a
Default Random selection

Hi,

Can you help me with this one??

In my mysql db i have a colum called names;

In names their are:

Frank
Frank
Bob
Alice
Bob
Alice
Jim
Alice
Frank

I want to make a random selection (max 3 value's for example).. Only it may not produce two times the same name. For example;

This is the output:

Frank, Jim, alice

Wrong output

Frank, Frank, Jim

Please help!

Thanks,

Frank


Reply With Quote
  #3 (permalink)  
Old 08-23-2003
Jim Lucas
 
Posts: n/a
Default Re: [PHP] Random selection

Try this:

SELECT name FROM table GROUP BY name ORDER BY RAND() LIMIT 3

This will group together all the names and then choose from a list that has
only unique names and then return 3 at random.

Jim Lucas

----- Original Message -----
From: <fkeessen@planet.nl>
To: <php-general@lists.php.net>
Sent: Saturday, August 23, 2003 6:06 AM
Subject: [php] Random selection


> Hi,
>
> Can you help me with this one??
>
> In my mysql db i have a colum called names;
>
> In names their are:
>
> Frank
> Frank
> Bob
> Alice
> Bob
> Alice
> Jim
> Alice
> Frank
>
> I want to make a random selection (max 3 value's for example).. Only it

may not produce two times the same name. For example;
>
> This is the output:
>
> Frank, Jim, alice
>
> Wrong output
>
> Frank, Frank, Jim
>
> Please help!
>
> Thanks,
>
> Frank
>
>
>



----------------------------------------------------------------------------
----


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


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:29 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0