Jump to content

Paging a randomly sorted list


deived

Recommended Posts

I'm not sure how to approach this one, so any help would be great.

I need to be able to display a long list of randomly sorted data using multiple pages.  The user will go to browse the content and the content will be sorted randomly.  Being that there is a lot of data it will need to be across multiple pages.  If the user goes back to the beginning of the browser function, the data will be displayed again, only it should be randomly resorted again.  It should keep that same sort when it goes to the next pages.

I know how to page content when pulling from a database, but I'm not sure how to approach it when that data is resorted randomly each time you begin.

I hope I'm making sense.  Any help?

Link to comment
Share on other sites

I don't have any code for this written yet.  I'm still trying to work the logic out for it.

 

It will be pulling from a MySQL database.  Of course a normal query will sort in the the order it is arranged in the database.  I'm not sure if it would be best to have the MySQL query do the random sorting, or if I should resort the results array with some PHP code.  As far as page refresh, if your on any other page than the first page, it should keep the same sorting that it is on so that the some of the data doesn't get repeated or skipped.  If your on the first page, or if you are starting a new BROWSE session, it would be OK to resort it then.

I don't necessarily need a code example for help right now, but some help on working out the logic would be great.

 

The project is for a talent casting company.  This will be on online portfolio of actors for directors to choose from.  We don't want to give preference to specific actors so we don't want the same actors to show up at the beginning of the search each time.  I figured it would be best to have the list randomized each time a director starts browsing through the list.  I could have just one long page with everyone, but that might be a bit much to handle.  I think they have a couple hundred actors.

Link to comment
Share on other sites

assuming your rows have a unique ID, you will need to modify your pagination to first select all IDs order by rand and then keep track of that list.  Store it in a temp table or temp file or as a session array.  Then, you're going to have to keep track of which "page" you are on (the offset and limit) through that list, and then for your actual mysql query, select the specific rows (..where id IN (a,b,c,...n) )  based on the ids.

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.