dbTalk Databases Forums  

rand()

comp.databases.mysql comp.databases.mysql


Discuss rand() in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Gary
 
Posts: n/a

Default rand() - 09-01-2006 , 06:27 PM






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!



Reply With Quote
  #2  
Old   
Gary
 
Posts: n/a

Default Re: rand() - 09-12-2006 , 06:46 PM






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" <hellsop (AT) ninehells (DOT) com> wrote

Quote:
On Fri, 1 Sep 2006 18:27:00 -0500, Gary wrote:
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?

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



Reply With Quote
  #3  
Old   
Gary
 
Posts: n/a

Default Re: Re: rand() - 09-23-2006 , 10:50 AM



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" <hellsop (AT) ninehells (DOT) com> wrote

Quote:
On Tue, 12 Sep 2006 18:46:02 -0500, Gary wrote:
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.

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.

"Peter H. Coffin" <hellsop (AT) ninehells (DOT) com> wrote in message
news:slrneg0544.748.hellsop (AT) abyss (DOT) ninehells.com...
On Fri, 1 Sep 2006 18:27:00 -0500, Gary wrote:
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?

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




--
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



Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.