Jump to content


Photo

RAND()


  • Please log in to reply
3 replies to this topic

#1 mcmuney

mcmuney
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 10 August 2006 - 01:01 AM

I'm using ORDER BY RAND() function, which works. The problem is that when results are > 10 and pagination is used, it randomizes the results on every page. I would like it to randomize once and when viewer goes to page 2, it should not randomize again. How can I achieve this? Thanks.

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 10 August 2006 - 01:05 AM

There is no good way of doing that.  The purpose of using RAND() is to get a different sort order each time.

The only thing I can think of off hand would be to do your query, then store the result somewhere...in a session, or in a file, so that when the user goes to the next page you are able to retrieve the same result set and get the next 10 records for them to view.

#3 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 10 August 2006 - 01:11 AM

Can you seed the random number that MySQL uses from some known point? If so you could just seed it from the same point twice, but I don't know enough about MySQL to know if you can.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 10 August 2006 - 01:16 AM

According to the manual, you can:

http://mysql.com/doc....html#id3220613

Which means that all he would have to do is get a random number, use it so seed mysql's RAND function, then store that number in a session to be used in all subsequent queries.

Good suggestion.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users