Random listing problem need help before weekend if possible

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

By willydoit - May 29, 2009

Hi Guys, hope you dont mind the cross post but there is obviously much more traffic in here than in the instant forum and my issue is fairly urgent before I continue working over the weekend.

[font "Verdana"]Hi,

I have a huge problem which will hopefully be easy to resolve, I have limited knowledge of cms builder and php so hope it is just a coding issue.

We have a number of accommodation sections and have set each section on the listings page to display 10 listings per page an example can be seen here
[url "http://www.interactivetools.com/forum/forum.cgi?url=http%3A%2F%2Fwww.interactivetools.com%2Fforum%2Fforum.cgi%3Furl%3Dhttp%253A%252F%252F79.170.44.106%252Fbridlington.net%252Flistings%252Fserviced_list.php"][font "Verdana"]http://79.170.44.106/bridlington.net/listings/serviced_list.php[/#003366][/url][font "Verdana"] (the site is in development so ignore any incidental issues). In this particular section of serviced accommodation we have 39 listings and we find that initial loading shows the page as being 1 of 4 which would seem to add up, however we are finding that throughout the 4 pages some accommodation is being listed a number of times and othewrs arent listed at all. (the site is being accessed by temperary measure so links to detail pages dont work unless bridlington.net/ is added to the path after the ip address but we assume this will be resolved when we change the nameserver details so the domain resolves)

I assumed that upon loading, the page would cache somewhere all the appropriate listings and pre create the required pages, however it seems as though when the next page is selected a new random listing is displayed each time so in effect instead of getting a full random list across 4 pages we are seeing 4 pages of random lists.

This facility is the only reason we upgraded from the numerous licences we have for listings manager so it is imperative that we get this working correctly otherwise I have wasted weeks of work spent getting to where we are now.

I appreciate weekend is coming up but pressures of work mean I will be working on this project over the weekend and would like to know that the issue can be resolved prior to going further down this route.

I feel certain it's something I have overlooked and hopefully a glance at the page above will enable someone with more knowledge than I to see exacxtly what I have done wrong.

I have attached the serviced_list.php file in case you need it in my post in the instant websites forum. (unable to access it at present as servers are off)

Thanks in advance

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: [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.