Jump to content

Selecting random records and holding for pagination


poleposters

Recommended Posts

Hi,

 

I'm building a business directory.When a user searches for a business I want the results to display randomly, as it would be unfair to order by date or alphabetically.

 

This is simple enough. Except I need to be able to save the random selection for pagination. This way there is no repeat of records and the user can view all  the records available.

 

Is this possible? And if so, can anyone help with some strategies?

 

Thanks.

Link to comment
Share on other sites

Hmmm.. Well I suppose you could store the displayed records in a session variable as an array for the current search term. So, store the ID's of the fields like so:

 

array(
"search_term" => array(
				"1" => array(1,7,4,89,41,22,14),
				"2" => array(65,32,51,3,8,18,29),
				),
);

 

Where you have the search term as the key then the value being another array. This array will hold the page data. So when you view the first page store all the ID's under the key 1 then when you go to the second page check that the selected IDs are NOT in that array, when displaying the records add them to the page 2 array. Then when you go back a page you could check to see if the page numbers key exists, if it does then display the records in the array, otherwise grab new records and check the array.

 

Make sense? I don't think there are any flaws with that idea. Then if they search again with the same term I suppose you could remove the array already in there and add a new one.

 

Good luck.

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.