Gossamer Forum
Home : Products : DBMan : Customization :

Custom sort of select top results

Quote Reply
Custom sort of select top results
For a set of returned results (business directory - see www.sussexfind.co.uk), I wish to always display Enhanced listings first at the top of the page.

At present I do this by simply sorting by ID and ensuring that Enhanced listings have ID numbers less than regular listings - the first 1000 ID's are reserved for this. Of course the problem is when there are 2 Enhanced listings returned for a visitors search. The first Enhanced listings is always the first result on the page, the second Enhanced listings is always the second and so on.

Has anyone got any ideas on how I can randomise this for just the Enhanced listings i.e. when the record ID is less than 1000?

Basically I need two sort orders - one for Enhanced listings, one for the rest. If I can do this I should be able to randomise it.

Thanks in advance, Brian
Quote Reply
Re: [omegadm] Custom sort of select top results In reply to
I think the change would have to be in db.cgi, in sub view_records. You would want to do two searches.

The first search would be for ID numbers that were less than 1000. You could then order them randomly after they are returned.

The second search would be for ID numbers that were greater than 1000.

At that point, you would combine the two results and send them to the html page.

The following is off the top of my head. I'm guaranteeing nothing! Wink

Code:

sub view_records {
# --------------------------------------------------------
# This is called when a user is searching the database for
# viewing. All the work is done in query() and the routines just
# checks to see if the search was successful or not and returns
# the user to the appropriate page.

$in{'ID'} = <1001;
my ($status1, @hits1) = &query("view");
if ($status1 eq "ok") {
$status = "ok";
# here is where you would randomize the results, which
# are in the array @hits1
}
$in{'ID'} = >1000;
my ($status2, @hits2) = &query("view");
if ($status2 eq "ok") {
$status = "ok";
# here you would combine array @hits1 (which has been randomized)
# and array @hits2, with @hits1 being first
# the resulting array should be called @hits
}
if ($status eq "ok") {

&html_view_success(@hits);
}
else {
&html_view_failure($status2);
}
}


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Custom sort of select top results In reply to
Nice one JP. I will have a play and post to the list when working.
Quote Reply
Re: [omegadm] Custom sort of select top results In reply to
I see one mistake I made. You need to put some quotation marks in.

$in{'ID'} = "<1001";
$in{'ID'} = ">1000";


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.

Last edited by:

JPDeni: Jul 1, 2005, 7:31 AM