Jump to content

RAND()


mcmuney

Recommended Posts

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

According to the manual, you can:

http://mysql.com/doc/refman/5.0/en/mathematical-functions.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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.