Random listing problem need help before weekend if possible

6 posts by 3 authors in: Forums > CMS Builder
Last Post: June 2, 2009   (RSS)

Re: [willydoit] Random listing problem need help before weekend if possible

By zip222 - May 29, 2009

I think the problem is entirely due to the fact that you are choosing to randomly display the listings and break them up over four pages. I can't imagine there is a way to do that without seeing some repeat listings, and others to not show up at all.

It also seems like an odd decision to order them this way from a usability standpoint. Every time someone returns to the listings they are going to be in a different order, which could make it difficult for them to find something they were looking at during a prior visit. I think listing these either alphabetically, or by date_updated would make more sense.

my 2 cents

Re: [willydoit] Random listing problem need help before weekend if possible

By Dave - May 29, 2009

One way to do it would be to output a long list in random order and then use a javascript widget to dynamically page through the content. You'd have to find the widget though.

Another way would be to have a custom script that would run once an minute or hour, etc that would set a random value is a "sortOrder" field which you could sort on. You'd still have the issue that someone who bookmarked page 2 one day and came back another would get different results.

Another way would be to add a random number to the query url, then pass that forward through links, and sort on the calculated MD5 of a column plus that number (it would essentially give unchanging random orders to different users that could be bookmarked). It might be slow if you had lots of records though.

So it's possible, but not simple or easy.

You may want to re-examine the purpose for having a multi-page record list in random order and see if there's another way to meet the same goal (eg: have 3 random listings in a sidebar on each page, etc). Even if you get it working, users may not find it very intuitive and may get confused as to what is happening.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [jdancisin] Random listing problem need help before weekend if possible

By willydoit - May 30, 2009

Hi Jdancisin and Dave,

I hear what you are saying, however after years of using Listings manager to display advertising for accommodation establishments the one gripe we would often hear was from establishments whos name started with a letter which appeared later in the alphabet, their gripe being that accommodation would often be chosen before getting to their section of the listings, going random was an ideal way of overcoming this and provided a fairer way of listing the advertisements although I agree that this approach wouldnt be as applicable for many other types of listings. We do have an accompanying search facility which will allow much shorter lists, so it may be that we have to elect to list all advertisements on a single page which does have advantages but just isn't as aesthetically pleasing.

Single page lists associated with pre filtered options (area , hotels, guesthouses etc) appears to be the simplest way to go.

Thanks to you all for helping me out before the weekend it ensures that I spend time on the right elements of getting the site completed.

Re: [willydoit] Random listing problem need help before weekend if possible

By Dave - June 1, 2009 - edited: June 2, 2009

Hi willydoit,

I thought of a (rather advanced) way to do it. It uses a little more CPU so it might not be a good solution if you have thousands and thousands of records but may be worth a try.

Add this code above your getRecords() code to assign a random number to each user:

// set random number for this user
@session_start();
if (!@$_SESSION['randNum']) { $_SESSION['randNum'] = rand(1,1000); }
$escapedRandNum = mysql_real_escape_string( $_SESSION['randNum'] );


Add this orderBy option to your viewer code to sort in a pseudo-random way that will stay the same between page loads (it may change again after an hour or so when the users session expires or they close their browser)

'orderBy' => "MD5(CONCAT(num, '$escapedRandNum'))",

Hope that helps!

Update: Removed extra debugging line from top code block.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Random listing problem need help before weekend if possible

By willydoit - June 2, 2009

Thanks Dave,

I will give this a try later today if possible, as accommodation is split across different tables we are unlikely to get more than a couple of hundred records at most so we will probably be able to live with the added cpu usage, providing we can demonstrate random listings for each new viewing this will be ideal. Will let you know how we get on. Thanks for the help it is appreciated.