Professional Web Applications Themes

rand() - MySQL

I've built a page in Dreamweaver (php) pulling records from mysql with rand() order, displaying 1 record at a time with a navigation pane, it correctly counts the number in the recordset, but when the user clicks on the navigation set to go to the next record, it sometimes repeats the records already shown. Is there a way to randomly sort a recordset, showing one record at a time, without repeating the ones shown? Thanks!...

  1. #1

    Default rand()

    I've built a page in Dreamweaver (php) pulling records from mysql with
    rand() order, displaying 1 record at a time with a navigation pane, it
    correctly counts the number in the recordset, but when the user clicks on
    the navigation set to go to the next record, it sometimes repeats the
    records already shown.

    Is there a way to randomly sort a recordset, showing one record at a time,
    without repeating the ones shown?

    Thanks!


    Gary Guest

  2. #2

    Default Re: rand()

    On Fri, 1 Sep 2006 18:27:00 -0500, Gary wrote: 

    Are you pulling records from a randomly-ordered record set, or are you
    plucking the top record off of a fresh randomly-ordered record set every
    time the next record is called for? The two are very different ways of
    doing things, and the latter will occasionally show the pattern you
    describe, while the former won't, at the disadvantage of eventually
    running out of random records.

    Another alternative is to remember the record last viewed in the php
    code and simply rerun your pull again if you get the same one again.

    --
    55. The deformed mutants and odd-ball psychotics will have their place in my
    Legions of Terror. However before I send them out on important covert
    missions that require tact and subtlety, I will first see if there is
    anyone else equally qualified who would attract less attention. --Overlord
    Peter Guest

  3. #3

    Default Re: rand()

    Only one record is being displayed at a time, but I think the page is being
    reloaded when the user clicks on the navigation bar ('NEXT') button, which
    would re-run the code to select a random record.

    Not sure how to do former suggestion without causing page to reload.

    Thanks for replying.


    "Peter H. Coffin" <com> wrote in message
    news:ninehells.com... 
    >
    > Are you pulling records from a randomly-ordered record set, or are you
    > plucking the top record off of a fresh randomly-ordered record set every
    > time the next record is called for? The two are very different ways of
    > doing things, and the latter will occasionally show the pattern you
    > describe, while the former won't, at the disadvantage of eventually
    > running out of random records.
    >
    > Another alternative is to remember the record last viewed in the php
    > code and simply rerun your pull again if you get the same one again.
    >
    > --
    > 55. The deformed mutants and odd-ball psychotics will have their place in
    > my
    > Legions of Terror. However before I send them out on important covert
    > missions that require tact and subtlety, I will first see if there is
    > anyone else equally qualified who would attract less
    > attention. --Overlord[/ref]


    Gary Guest

  4. #4

    Default OT: Re: rand()

    On Tue, 12 Sep 2006 18:46:02 -0500, Gary wrote: 
    The cheap way would be to make the NEXT button pass back (via either GET
    or POST) the unique id for the record currently being displayed, and
    have the query use a WHERE uniq_id <> '$old_uniq_id' in its selection
    criteria...

    You might still end up with a A C F E B E B D pattern, but that's
    probably *slightly* less obnoxious than a A C F F F F B D pattern...

    Of course, there's lots and lots of far more complicated ways of
    extending that into things like "exclude the last 5 records hit" or
    "exclude the last (10% of COUNT(*)) records", or endless other ways of
    making rand() even less random in ways that are happy.

    Once I cheated and made a new column that contained a "next_random"
    column and simply had a little program regenerate the linked list
    occasionally.
     
    >>
    >> Are you pulling records from a randomly-ordered record set, or are you
    >> plucking the top record off of a fresh randomly-ordered record set every
    >> time the next record is called for? The two are very different ways of
    >> doing things, and the latter will occasionally show the pattern you
    >> describe, while the former won't, at the disadvantage of eventually
    >> running out of random records.
    >>
    >> Another alternative is to remember the record last viewed in the php
    >> code and simply rerun your pull again if you get the same one again.
    >>
    >> --
    >> 55. The deformed mutants and odd-ball psychotics will have their place in
    >> my
    >> Legions of Terror. However before I send them out on important covert
    >> missions that require tact and subtlety, I will first see if there is
    >> anyone else equally qualified who would attract less
    >> attention. --Overlord[/ref]
    >
    >[/ref]


    --
    100. Finally, to keep my subjects permanently locked in a mindless trance, I
    will provide each of them with free unlimited Internet access.
    --Peter Anspach's list of things to do as an Evil Overlord
    Peter Guest

  5. #5

    Default Re: Re: rand()

    Thanks for the ideas, I was thinking a solution might be to create a
    temporary table, copy in all the records, and pull the displayed records
    randomly from that, and have a delete function on the next button, so the
    temporary table would only contain the records not shown.

    What do you think?


    "Peter H. Coffin" <com> wrote in message
    news:ninehells.com... 
    > The cheap way would be to make the NEXT button pass back (via either GET
    > or POST) the unique id for the record currently being displayed, and
    > have the query use a WHERE uniq_id <> '$old_uniq_id' in its selection
    > criteria...
    >
    > You might still end up with a A C F E B E B D pattern, but that's
    > probably *slightly* less obnoxious than a A C F F F F B D pattern...
    >
    > Of course, there's lots and lots of far more complicated ways of
    > extending that into things like "exclude the last 5 records hit" or
    > "exclude the last (10% of COUNT(*)) records", or endless other ways of
    > making rand() even less random in ways that are happy.
    >
    > Once I cheated and made a new column that contained a "next_random"
    > column and simply had a little program regenerate the linked list
    > occasionally.

    >>
    >>[/ref]
    >
    >
    > --
    > 100. Finally, to keep my subjects permanently locked in a mindless trance,
    > I
    > will provide each of them with free unlimited Internet access.
    > --Peter Anspach's list of things to do as an Evil Overlord[/ref]


    Gary Guest

  6. #6

    Default Re: rand()

    On Sat, 23 Sep 2006 10:50:38 -0500, Gary wrote: 

    The challenge is that temporary tables only last for the duration of the
    database connection, and for web applications, it's very difficult to
    know beforehand exactly how long that connection is going to last. Even
    a "persistant" connection may vanish if someone steps away from the
    browser for a while.

    --
    Either way, it'll remind the clued that there's only one letter
    difference between 'turkey' and 'turnkey'.
    -- Mike Andrews
    Peter Guest

Similar Threads

  1. #40187 [NEW]: mt_rand(), rand()
    By callawey at gmail dot com in forum PHP Bugs
    Replies: 3
    Last Post: January 21st, 07:18 PM
  2. what is rand?
    By Amelyan in forum ASP.NET Building Controls
    Replies: 1
    Last Post: March 31st, 04:05 AM
  3. #25639 [Com]: problem with rand()
    By paul dot vaughan at weston dot ac dot uk in forum PHP Development
    Replies: 0
    Last Post: October 8th, 01:33 PM
  4. Trying to get a random rand
    By marcel in forum ASP Database
    Replies: 1
    Last Post: August 18th, 03:16 AM

Bookmarks

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