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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.