Ask a Question related to PHP Programming, Design and Development.

  1. #1

    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

    Binay Agarwal Guest

  2. Similar Questions and Discussions

    1. Using Math.random to go to random frames
      Hello everyone. My cerebral density is preventing me from seeing the solution to this problem. I have the following code which causes the user to...
    2. Random frame selection?
      I have just started using Director, so this is probably a simple/stupid question. Anyway, I am doing a short story in which the user can interact...
    3. Random Button Selection
      I am creating a CDROM presentation using Director MX (Mac/PC delivery). This presentation has a couple of sections that have a number of buttons that...
    4. Disconected Recordset & Random Selection
      Hello All, How would I go about using a disconnect recordset and select (x) records from it, x being the number of records to be selected. ...
    5. Random image in a random place.
      Anyone know javascript? I have a grid(4 x 4) of 16 spacer images and a few text links on the side. Each text link represents a different folder of...
  3. #2

    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


    fkeessen@planet.nl Guest

  4. #3

    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
    Jim Lucas Guest

  5. #4

    Default Random selection

    I have a number of details stored in an xml document that I use to dynamically
    create content on a webpage. I have sorted it so only four items are displayed.

    All fine and dany so far and working a treat.

    What I want to know is, is it possible to randomly select four items from the
    xml files each time the page is accessed or refreshed

    If it is any help the code I am using at present in the xsl file is here;

    <xslaram name="itemsPerPage" select="5" />
    <xsl:template match="/">
    <h1><xsl:value-of select="rss/channel/title"/></h1>
    <div id="intro"><xsl:value-of select="rss/channel/description"
    disable-output-escaping="yes"/></div><br /><!--<p>-->

    <xsl:for-each select="rss/channel/item[position() <= $itemsPerPage]">

    <h2><xsl:value-of select="title"/></h2>
    <div id="dateShow">Date posted - <xsl:value-of select="pubDate"/></div>
    <p><xsl:value-of select="description" disable-output-escaping="yes"/><br
    /><a href="{link}">more . . .</a></p><br />
    </xsl:for-each>

    <p><a href="#">More NEWS :: EVENTS :: UPDATES</a></p>
    <!--</p>-->

    </xsl:template>

    pwiop Guest

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139