Help to stop randomizing search results across mulitple pages

4 posts by 2 authors in: Forums > CMS Builder
Last Post: September 15, 2010   (RSS)

Hey guys,

We have our results viewers setup to show all of our listings randomly. We have it setup this way in order to allow our customers to have an "equal" chance at getting there listings seen. The problem we run into is that once a user goes to a second page in the results and clicks the previous button or clicks the back button in their browser the Random function "re-randomizes" the results making the search not very usable. We want to do something that only randomizes the listings once for a particular user. Or maybe remembers where the listings were as the user clicks through the multiple pages of results.

We do not require potential renters to setup an account so they are not logged into our system in any way. I think this could be setup using cookies or better yet sessions?

thanks!
Lauren
Jason Glass

Re: [rentittoday] Help to stop randomizing search results across mulitple pages

By Chris - September 13, 2010 - edited: September 15, 2010

Hi Lauren,

Here's a sneaky solution for you.

// if the visitor doesn't have a random_string, assign them a new one
if (!@$_SESSION['random_string']) { $_SESSION['random_string'] = uniqid(''); }

// load records
list($exampleRecords, $exampleMetaData) = getRecords(array(
'tableName' => 'example',
'perPage' => '5',
'orderBy' => mysql_escapef('MD5(CONCAT(?, num))', $_SESSION['random_string']),
));


Does that help? Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Help to stop randomizing search results across mulitple pages

Thanks for the response!
We added this code and are getting a
"Notice: Undefined index: random_string...." error.

I am not that familiar with this sessions stuff. But, from what I assume we are getting this error because "random_string" is not defined anywhere. The issue is we do not know where or how to define this variable correctly.

Any more help would be greatly appreciated :)

Lauren
Jason Glass